Function: createGuards()
ts
function createGuards<T, G>(defaults?): GuardsFor<TypesOf<T>, G>;Defined in: packages/hono/src/guards.ts:210
Builds the guards with shared defaults (e.g. a custom onForbidden that renders an HTML page).
Pass the same type argument as createRbac<AppTypes>() (or typeof rbac) to check names at compile time: const { requirePermission } = createGuards<AppTypes>(). The handlers (defaults and per-guard options) then get a c whose c.var.rbac has the same names.
With per-guard names (RbacTypeConfig['guards']), G is the guard of the requests these guards run on (the middleware's guard; default: the default guard): createGuards<AppRbac, 'api'>(). Names are checked in that guard, or in a route's { guard }. It is a type only; the middleware's guard still decides at runtime.
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends RbacTypeConfig | Rbac<RbacTypeConfig> | DefaultRbacTypes |
G extends string | DefaultGuardName<TypesOf<T>> & GuardName<TypesOf<T>> |
Parameters
| Parameter | Type |
|---|---|
defaults? | GuardHandlers<GuardHandlerContext<TypesOf<T>, G>> |
Returns
GuardsFor<TypesOf<T>, G>
