Skip to content

rolesAuthorization

function rolesAuthorization(options?): AuthorizationProvider;

Defined in: authorization/roles.ts:90

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/flags/authorization/roles";
// Built-in admin/editor/viewer policy:
const authz = rolesAuthorization();
// Custom policy:
const custom = rolesAuthorization({
policy: {
ops: ["snapshot:publish", "snapshot:rollback", "snapshot:read"],
auditor: ["audit:read"],
},
});