Skip to content

Function: getRbac() ​

ts
function getRbac<T, G>(context): 
  | SubjectRbac<TypesOf<T>, ScopedGuardName<TypesOf<T>, G>>
  | null;

Defined in: packages/nestjs/src/context.ts:71

Returns the SubjectRbac that RbacGuard resolved for this execution context (null for guests). Throws RbacGuardMissingError when the guard has not run.

getRbac<AppRbac>(context) (or getRbac<typeof rbac>(context)) types it with the engine's names. With per-guard names, getRbac<AppRbac, 'api'>(context) types it with the names of guard api (the guard of RbacModule); the default guard's names without it.

Type Parameters ​

Type ParameterDefault type
T extends RbacTypeConfig | Rbac<RbacTypeConfig>DefaultRbacTypes
G extends stringDefaultGuardName<TypesOf<T>>

Parameters ​

ParameterType
contextExecutionContext

Returns ​

| SubjectRbac<TypesOf<T>, ScopedGuardName<TypesOf<T>, G>> | null

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