Skip to content

Interface: RoleGuardOptions<R> ​

Defined in: packages/trpc/src/guards.ts:109

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 subject's guard comes from createRbacContext() (or resolve). With per-guard names, tell the types which guard the subjects have with createGuards<AppRbac, 'api'>().

Extends ​

Type Parameters ​

Type ParameterDefault type
RSubjectRbac

Properties ​

PropertyTypeDescriptionInherited fromDefined in
all?booleanRequire ALL of the roles (instead of any). Default: false.-packages/trpc/src/guards.ts:111
exposeRequirements?booleanInclude the required roles/permissions in the default error (required in its body). Default: false (like spatie's display_permission_in_exception).RouteGuardOptions.exposeRequirementspackages/trpc/src/guards.ts:71
guard?stringCheck in this guard instead of the subject's (subject.withScope({ guard })), like spatie's role:admin,api. Default: the guard of the subject.RouteGuardOptions.guardpackages/trpc/src/guards.ts:101
onForbidden?GuardHandler<R>Called when the subject lacks access. Default: a TRPCError FORBIDDEN.RouteGuardOptions.onForbiddenpackages/trpc/src/guards.ts:66
onUnauthenticated?GuardHandler<R>Called when there is no subject (ctx.rbac is null). Default: a TRPCError UNAUTHORIZED.RouteGuardOptions.onUnauthenticatedpackages/trpc/src/guards.ts:64

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