Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Simple RBAC system with route guard by user's role #52

Open
fasenderos opened this issue Mar 12, 2021 · 3 comments
Open

[Question] Simple RBAC system with route guard by user's role #52

fasenderos opened this issue Mar 12, 2021 · 3 comments

Comments

@fasenderos
Copy link

fasenderos commented Mar 12, 2021

Is it possible to define a simple RBAC system ('USER', 'EDITOR', 'ADMIN') and guarding the routes by user's role without having to define all permissions? Something like:

# app.roles.ts
import { RolesBuilder } from 'nest-access-control';
export enum AppRoles {
  USER = 'USER',
  EDITOR = 'EDITOR',
  ADMIN = 'ADMIN',
}
export const roles: RolesBuilder = new RolesBuilder();
roles
  .grant(AppRoles.USER)
  .grant(AppRoles.EDITOR)
  .extend(AppRoles.USER)  
  .grant(AppRoles.ADMIN)
  .extend(AppRoles.EDITOR)


# app.controller.ts
@Get('test')
@UseGuards(JwtAuthGuard, ACGuard)
@UseRoles({role: 'ADMIN'})  //  <=== Only admin access
test() {
   ...
}

I see that in the original interface can be defined the role property that sounds good for my case, but it seems that your role.interface.ts accept only resource, action and possession. Or I'm missing something?

Thanks in advance

@nunnally
Copy link

Hello @fasenderos you got something about that?

@mkubdev
Copy link

mkubdev commented Sep 30, 2021

Hi @fasenderos, same as @nunnally !

@ernes128
Copy link

Hello @fasenderos you could follow the official RBAC simple example in the nest official docs. https://docs.nestjs.com/security/authorization I think is a great fit for the use case you are asking 🤓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants