Function: createRbacServer()
ts
function createRbacServer<T, G, A>(options): RbacServer<T, G, A>;Defined in: packages/astro/src/server.ts:231
Creates the server side of the integration: getRbac(context), getSnapshot(context) and the guards, for pages, endpoints and middleware. A guard resolves to undefined when the check passes, and to a Response to return otherwise: a 401 or 403 JSON response, or a redirect.
ts
// src/rbac.ts
export const rbacServer = createRbacServer({
rbac,
getSubject: ({ locals }) => (locals.user ? { type: 'user', id: locals.user.id } : null),
unauthenticatedRedirect: '/login',
})astro
---
// src/pages/admin.astro
const denied = await rbacServer.requireRole(Astro, 'admin')
if (denied) return denied
---Type Parameters
| Type Parameter | Default type |
|---|---|
T extends RbacTypeConfig | DefaultRbacTypes |
G extends string | DefaultGuardName<T> & GuardName<T> |
A extends AstroContext | AstroContext |
Parameters
| Parameter | Type |
|---|---|
options | RbacServerOptions<T, G, A> & (T extends object ? GuardOptions<CheckGuard<T, G>> : unknown) |
Returns
RbacServer<T, G, A>
