Skip to content

Interface: RoleGuardOptions<Req> ​

Defined in: packages/express/src/guards.ts:81

The options every guard takes: the handlers plus guard.

guard is per guard only (like spatie's role:admin,api), not a createGuards() default: the defaults are about handlers, and the request's guard is set on the middleware. With per-guard names, tell the types which guard the requests have with createGuards<AppRbac, 'api'>().

Extends ​

Type Parameters ​

Type ParameterDefault type
ReqRequest

Properties ​

PropertyTypeDescriptionInherited fromDefined in
all?booleanRequire ALL of the roles (instead of any). Default: false.-packages/express/src/guards.ts:83
exposeRequirements?booleanInclude the required roles/permissions in the default 403 body. Default: false (like spatie's display_permission_in_exception).RouteGuardOptions.exposeRequirementspackages/express/src/guards.ts:58
guard?stringCheck in this guard instead of the request's (subject.withScope({ guard })), like spatie's role:admin,api. Default: the guard of the request's subject.RouteGuardOptions.guardpackages/express/src/guards.ts:73
onForbidden?GuardHandler<Req>Called when the subject lacks access. Default: 403 JSON.RouteGuardOptions.onForbiddenpackages/express/src/guards.ts:53
onUnauthenticated?GuardHandler<Req>Called when there is no subject (req.rbac is null). Default: 401 JSON.RouteGuardOptions.onUnauthenticatedpackages/express/src/guards.ts:51

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