Skip to content

Variable: rbacPlugin ​

ts
const rbacPlugin: FastifyPluginAsync<RbacPluginOptions>;

Defined in: packages/fastify/src/plugin.ts:131

Fastify plugin that resolves the current subject and sets request.rbac (a SubjectRbac, or null for guests).

Wrapped with fastify-plugin, so the hook applies to the context it is registered in (register it inside an encapsulated plugin to scope it, e.g. per guard or per team).

ts
await app.register(rbacPlugin, { rbac, getSubject: (req) => (req.user ? { type: 'user', id: req.user.id } : null) })

To type request.rbac with the names of a typed engine, register it in RbacRegister (or type a handler's request as RbacRequest).

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