Skip to content

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 ParameterDefault type
T extends RbacTypeConfigDefaultRbacTypes
G extends stringDefaultGuardName<T>

Parameters ​

ParameterType
optionsRbacPluginOptions<T, G> & (T extends object ? GuardOptions<CheckGuard<T, G>> : unknown)

Returns ​

Elysia<"", { }, { }, { }, { }, { }, { }>

Released under the MIT License. Inspired by spatie/laravel-permission.