Function: createRbacServer()
ts
function createRbacServer<T, G>(options): RbacServer<T, G>;Defined in: packages/tanstack-start/src/server.ts:205
Creates the server side of the integration: getRbac(request), getSnapshot(request) and the guards, for server functions, middleware and server routes. Guards resolve to the subject when the check passes, and throw a Response otherwise: a 401 or 403 JSON response, or what onUnauthenticated / onForbidden return.
ts
// src/rbac.ts
export const rbacServer = createRbacServer({
rbac,
getSubject: async (request) => {
const user = await getUser(request)
return user ? { type: 'user', id: user.id } : null
},
})
// a server function
export const getStats = createServerFn().handler(async () => {
await rbacServer.requireRole(getRequest(), 'admin')
return loadStats()
})Type Parameters
| Type Parameter | Default type |
|---|---|
T extends RbacTypeConfig | DefaultRbacTypes |
G extends string | DefaultGuardName<T> & GuardName<T> |
Parameters
| Parameter | Type |
|---|---|
options | RbacServerOptions<T, G> & (T extends object ? GuardOptions<CheckGuard<T, G>> : unknown) |
Returns
RbacServer<T, G>
