Skip to main content
Version: 3.x (deprecated)

Authorization without surprises

@rbac/rbac is a TypeScript library for role-based access control in Node.js. Give roles permission to perform operations, optionally inherit permissions from other roles, then ask the library whether an operation is allowed.

It handles authorization, not authentication: your application identifies the user, determines the user's trusted role, and supplies any required context. RBAC returns a decision; your application enforces it.

A complete decision​

ts
import RBAC from '@rbac/rbac';

const rbac = RBAC()({
  viewer: { can: ['documents:read'] },
  editor: { inherits: ['viewer'], can: ['documents:edit'] }
});

console.log(await rbac.can('editor', 'documents:read')); // true
console.log(await rbac.can('viewer', 'documents:edit')); // false
console.log(await rbac.can('unknown', 'documents:read')); // false

RBAC(config)(roles) returns an instance with can(), addRole(), and updateRoles(). Permission checks always return a promise, even for unconditional grants. Undefined roles and missing grants are denied by default.

What the library provides​

CapabilityRelevant guide
Exact permissions, inheritance, repeated conditional grantsRoles and permissions
Wildcards and regular expressionsPatterns
Request-aware rules and asynchronous predicatesConditions
Runtime role managementRuntime changes
Tenant-based persistenceDatabase adapters
Express, NestJS, FastifyMiddleware

Continue with installation, or try the interactive playground.