nestjs-prisma-starter
nestjs-prisma-starter copied to clipboard
Add role guard and decorator to support RBAC
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);
}
// ...
}