Skip to content

Interface: RoleGuardOptions<A> ​

Defined in: packages/react-router/src/server.ts:100

The options every guard takes as its last argument: the handlers plus guard. They win over the defaults.

Extends ​

Type Parameters ​

Type ParameterDefault type
A extends RouteArgsRouteArgs

Properties ​

PropertyTypeDescriptionInherited fromDefined in
all?booleanRequire ALL of the roles (instead of any). Default: false.-packages/react-router/src/server.ts:102
exposeRequirements?booleanInclude the required roles/permissions in the default 403 body (required). Default: false (like spatie's display_permission_in_exception).RouteGuardOptions.exposeRequirementspackages/react-router/src/server.ts:86
forbiddenRedirect?string | ((args) => string)Redirect users without access here (302) instead of the 403.RouteGuardOptions.forbiddenRedirectpackages/react-router/src/server.ts:81
guard?stringCheck in this guard instead of the server's (subject.withScope({ guard })), like spatie's role:admin,api.RouteGuardOptions.guardpackages/react-router/src/server.ts:92
onForbidden?GuardHandler<A>Called when the subject lacks access. Wins over forbiddenRedirect. Default: a 403 JSON Response.RouteGuardOptions.onForbiddenpackages/react-router/src/server.ts:74
onUnauthenticated?GuardHandler<A>Called when there is no subject. Wins over unauthenticatedRedirect. Default: a 401 JSON Response.RouteGuardOptions.onUnauthenticatedpackages/react-router/src/server.ts:72
unauthenticatedRedirect?string | ((args) => string)Redirect guests here (302) instead of the 401. Handy for page loaders: '/login'. A function gets the args, e.g. to keep the page: ({ request }) => /login?redirectTo=${new URL(request.url).pathname}``.RouteGuardOptions.unauthenticatedRedirectpackages/react-router/src/server.ts:79

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