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)

RBAC 2.x

This is the historical documentation for the 2.x series, based on its final npm release, 2.2.3. It covers 2.0.0–2.2.3; some features shown here may not be available in early 2.x minors.

Deprecated: 2.x is no longer maintained. Use 3.x (latest) for new projects and follow the 2.x → 3.x migration guide for existing integrations.

Compared with 1.x, 2.x is written in TypeScript and ships .d.ts declarations. It supports runtime role updates, conditional permissions, database adapters, Express/NestJS/Fastify middleware and tenant-scoped role loading.

ts
import RBAC from '@rbac/rbac';

const auth = RBAC<{ owner: boolean }>()({
  viewer: { can: ['documents:read'] },
  editor: {
    inherits: ['viewer'],
    can: [{ name: 'documents:edit', when: ({ owner }) => owner }]
  }
});

console.log(await auth.can('editor', 'documents:read')); // true
console.log(await auth.can('editor', 'documents:edit', { owner: true })); // true

See installation, roles, conditions, integrations and the 2.2.3 API snapshot.