Skip to content

Function: createGuards() ​

ts
function createGuards<T, G>(defaults?): GuardsFor<TypesOf<T>, G>;

Defined in: packages/elysia/src/guards.ts:188

Builds the guards with shared defaults (e.g. a custom onForbidden).

Pass the same type argument as createRbac<AppTypes>() (or typeof rbac) to check names at compile time: const { requirePermission } = createGuards<AppTypes>(). With per-guard names, G is the guard of the requests these guards run on: createGuards<AppRbac, 'api'>().

Type Parameters ​

Type ParameterDefault type
T extends RbacTypeConfig | Rbac<RbacTypeConfig>DefaultRbacTypes
G extends stringDefaultGuardName<TypesOf<T>> & GuardName<TypesOf<T>>

Parameters ​

ParameterType
defaults?GuardHandlers<GuardHandlerContext<TypesOf<T>, G>>

Returns ​

GuardsFor<TypesOf<T>, G>

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