Skip to content

Interface: RouteGuardOptions<C> ​

Defined in: packages/hono/src/guards.ts:71

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 ​

Extended by ​

Type Parameters ​

Type ParameterDefault type
CContext

Properties ​

PropertyTypeDescriptionInherited fromDefined in
exposeRequirements?booleanInclude the required roles/permissions in the default 403 body. Default: false (like spatie's display_permission_in_exception).GuardHandlers.exposeRequirementspackages/hono/src/guards.ts:61
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.-packages/hono/src/guards.ts:76
onForbidden?GuardHandler<C>Called when the subject lacks access. Default: 403 JSON.GuardHandlers.onForbiddenpackages/hono/src/guards.ts:56
onUnauthenticated?GuardHandler<C>Called when there is no subject (c.var.rbac is null). Default: 401 JSON.GuardHandlers.onUnauthenticatedpackages/hono/src/guards.ts:54

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