Skip to content

Interface: RoleGuardOptions ​

Defined in: packages/sveltekit/src/server/guards.ts:91

The options every guard takes as its last argument: the handlers plus guard. A guard's own handlers win over the defaults of createGuards().

Extends ​

Properties ​

PropertyTypeDescriptionInherited fromDefined in
all?booleanRequire ALL of the roles (instead of any). Default: false.-packages/sveltekit/src/server/guards.ts:93
exposeRequirements?booleanInclude the required roles/permissions in the default 403 body (required). Default: false (like spatie's display_permission_in_exception).RouteGuardOptions.exposeRequirementspackages/sveltekit/src/server/guards.ts:71
forbiddenRedirect?stringRedirect users without access here (redirect(303, url)) instead of the 403 error.RouteGuardOptions.forbiddenRedirectpackages/sveltekit/src/server/guards.ts:66
guard?stringCheck in this guard instead of the request's (subject.withScope({ guard })), like spatie's role:admin,api. Default: the guard of rbacHandle().RouteGuardOptions.guardpackages/sveltekit/src/server/guards.ts:83
onForbidden?GuardHandlerCalled when the subject lacks access. Wins over forbiddenRedirect. Default: error(403, { error: 'FORBIDDEN', reason, message }).RouteGuardOptions.onForbiddenpackages/sveltekit/src/server/guards.ts:62
onUnauthenticated?GuardHandlerCalled when there is no subject (event.locals.rbac is null). Wins over unauthenticatedRedirect. Default: error(401, { error: 'UNAUTHENTICATED', message }).RouteGuardOptions.onUnauthenticatedpackages/sveltekit/src/server/guards.ts:57
unauthenticatedRedirect?stringRedirect guests here (redirect(303, url)) instead of the 401 error. Handy for page loads: '/login'.RouteGuardOptions.unauthenticatedRedirectpackages/sveltekit/src/server/guards.ts:64

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