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

API reference — 1.1.0

This is a historical API snapshot based on the published 1.1.0 package and README, not the generated 3.x TypeDoc reference.

APIMeaning
require('@rbac/rbac')Load the JavaScript factory.
RBAC(config?)(roles)Create an authorization instance.
roles[role].canArray of permission strings or conditional { name, when } entries.
roles[role].inheritsOptional array of roles whose permissions are inherited.
auth.can(role, operation, params?)Check authorization asynchronously.
config.enableLoggerEnable or disable decision logging.
config.loggerOverride the logging function.
js
const RBAC = require('@rbac/rbac');
const auth = RBAC({ enableLogger: false })({
  viewer: { can: ['reports:read'] }
});

auth.can('viewer', 'reports:read').then(console.log); // true

TypeScript declarations, addRole, updateRoles, database adapters and framework middlewares are not part of the published 1.x API. See the 1.x to 2.x migration guide before using them.