Skip to content

Class: RbacGuard ​

Defined in: packages/nestjs/src/guard.ts:42

Resolves the current subject (once per request) and enforces the @RequirePermissions(), @RequireRoles() and @RequireRoleOrPermission() metadata of the class and the handler. A requirement with { guard } is checked in that guard (subject.withScope({ guard })).

  • no subject → UnauthorizedException 401 { error: 'UNAUTHENTICATED', message }
  • missing access → ForbiddenException 403 { error: 'FORBIDDEN', reason, message }

Bodies are identical to @anievo-id/rbac-evolution-express.

Implements ​

  • CanActivate

Constructors ​

Constructor ​

ts
new RbacGuard(reflector, options): RbacGuard;

Defined in: packages/nestjs/src/guard.ts:44

Parameters ​

ParameterType
reflectorReflector
optionsRbacModuleOptions

Returns ​

RbacGuard

Methods ​

canActivate() ​

ts
canActivate(context): Promise<boolean>;

Defined in: packages/nestjs/src/guard.ts:49

Parameters ​

ParameterTypeDescription
contextExecutionContextCurrent execution context. Provides access to details about the current request pipeline.

Returns ​

Promise<boolean>

Value indicating whether or not the current request is allowed to proceed.

Implementation of ​

CanActivate.canActivate

Released under the MIT License. Inspired by spatie/laravel-permission.