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

Add role guard and decorator to support RBAC #465

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zlwu
Copy link
Contributor

@zlwu zlwu commented Aug 24, 2022

Add RolesGuard guard and and Roles decorator to support Role-Based Access Control.

This is an example for users with role USER or ADMIN can call updateUser().

@Resolver(() => User)
@UseGuards(GqlAuthGuard)
export class UsersResolver {

  // ...


  @Roles(Role.USER, Role.ADMIN)
  @UseGuards(GqlAuthGuard, RolesGuard)
  @Mutation(() => User)
  async updateUser(
    @UserEntity() user: User,
    @Args('data') newUserData: UpdateUserInput
  ) {
    return this.usersService.updateUser(user.id, newUserData);
  }

  // ...
}

@zlwu zlwu changed the title add role guard and decorator Add role guard and decorator to support RBAC Aug 24, 2022
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

Successfully merging this pull request may close these issues.

1 participant