Function: rbacPlugin()
ts
function rbacPlugin<T, G>(options): Elysia<"", {
}, {
}, {
}, {
}, {
}, {
}>;Defined in: packages/elysia/src/plugin.ts:75
Resolves the current subject and adds rbac (a SubjectRbac, or null for guests) to the context of every route registered after it.
ts
const app = new Elysia()
.use(rbacPlugin({ rbac, getSubject: ({ headers }) => (headers['x-user'] ? { type: 'user', id: headers['x-user'] } : null) }))
.get('/me', ({ rbac }) => rbac?.getRoleNames() ?? [])Type Parameters
| Type Parameter | Default type |
|---|---|
T extends RbacTypeConfig | DefaultRbacTypes |
G extends string | DefaultGuardName<T> |
Parameters
| Parameter | Type |
|---|---|
options | RbacPluginOptions<T, G> & (T extends object ? GuardOptions<CheckGuard<T, G>> : unknown) |
Returns
Elysia<"", { }, { }, { }, { }, { }, { }>
