Skip to main content
Deprecated version. We recommend upgrading to 4.x (latest). Follow the migration guides: 2.x to 3.x · 3.x to 4.x.
Version: 2.x (deprecated)

API reference — 2.2.3

This historical snapshot is based on the published 2.2.3 TypeScript declarations. It is independent of the generated 3.x API reference.

API2.2.3 contract
RBAC<P>(config?)(roles)Create an authorization instance.
auth.can(role, operation, params?)Return Promise<boolean>. Operation accepts string | RegExp.
auth.updateRoles(roles)Update the in-memory role map.
auth.addRole(name, role)Add or replace an in-memory role.
Role<P>{ can: Array<string | { name, when }>, inherits?: string[] }.
When<P>Boolean, promise, predicate or Node-style callback.
RBACConfiglogger?, enableLogger?, colors?.
createTenantRBAC(adapter, tenantId, config?)Build an RBAC instance from adapter-backed roles.
createExpressMiddleware, createNestMiddleware, createFastifyMiddlewareFramework integration factories exported from the package root.
ts
import RBAC from '@rbac/rbac';

const auth = RBAC<{ approved: boolean }>()({
  reviewer: { can: [{ name: 'reviews:accept', when: ({ approved }) => approved }] }
});

console.log(await auth.can('reviewer', 'reviews:accept', { approved: true })); // true

2.2.3 publishes a root-only exports map. Later features such as the @rbac/rbac/helpers and /schemas subpaths and the Nest guard belong to 3.x, not this historical snapshot.