Function: createGuards()
Call Signature
function createGuards<T, G>(options): GuardsFor<TypesOf<T>, G, any>;Defined in: packages/trpc/src/guards.ts:260
Builds the guards with shared options: handlers (e.g. an onForbidden that throws NOT_FOUND), and a resolve that reads the subject of a call instead of ctx.rbac.
Pass the same type argument as createRbac<AppRbac>() (or typeof rbac) to check names at compile time: const { requirePermission } = createGuards<AppRbac>(). After a guard, ctx.rbac has the same names and is never null.
With per-guard names (RbacTypeConfig['guards']), G is the guard of the subjects these guards check (the guard of createRbacContext(); default: the default guard): createGuards<AppRbac, 'api'>(). Names are checked in that guard, or in a procedure's { guard }. It is a type only; the subject'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 |
|---|---|
options | CreateGuardsOptions<GuardSubject<T, G>> & object |
Returns
Call Signature
function createGuards<T, G>(defaults?): GuardsFor<TypesOf<T>, G>;Defined in: packages/trpc/src/guards.ts:266
Builds the guards with shared options: handlers (e.g. an onForbidden that throws NOT_FOUND), and a resolve that reads the subject of a call instead of ctx.rbac.
Pass the same type argument as createRbac<AppRbac>() (or typeof rbac) to check names at compile time: const { requirePermission } = createGuards<AppRbac>(). After a guard, ctx.rbac has the same names and is never null.
With per-guard names (RbacTypeConfig['guards']), G is the guard of the subjects these guards check (the guard of createRbacContext(); default: the default guard): createGuards<AppRbac, 'api'>(). Names are checked in that guard, or in a procedure's { guard }. It is a type only; the subject'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<GuardSubject<T, G>> |
