rolesAuthorization
function rolesAuthorization<Action, Resource>(options): AuthorizationProvider<Action, Resource>;Defined in: src/authorization/roles.ts:55
Create a role-based AuthorizationProvider.
Decision order:
- If
readonlyand the action mutates → deny. - If the principal is
null→ deny. - If any of the principal’s roles grants the action (via
"*"or an explicit list) → allow; otherwise deny.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
Action extends string |
string |
Resource |
unknown |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
RolesAuthorizationOptions<Action> |
Returns
Section titled “Returns”AuthorizationProvider<Action, Resource>
Example
Section titled “Example”import { rolesAuthorization } from "@xtandard/kit/authorization/roles";
const authz = rolesAuthorization({ actions, // from defineActions(...) policy: { admin: "*", viewer: ["endpoint:read", "message:read"] },});