Skip to content

rolesAuthorization

function rolesAuthorization(options?): AuthorizationProvider;

Defined in: src/authorization/roles.ts:99

Create a role-based AuthorizationProvider.

Decision order:

  1. If readonly and the action mutates → deny.
  2. If the principal is null → deny.
  3. If any of the principal’s roles grants the action (via "*" or an explicit list) → allow; otherwise deny.
Parameter Type
options? RolesAuthorizationOptions

AuthorizationProvider

import { rolesAuthorization } from "@xtandard/audit/authorization/roles";
// Built-in admin/auditor/viewer policy:
const authz = rolesAuthorization();
// Custom policy:
const custom = rolesAuthorization({
policy: {
support: ["tenant:read", "event:read"],
compliance: ["event:read", "event:export", "event:erase"],
},
});