delegatedAuthorization
function delegatedAuthorization(options): AuthorizationProvider;Defined in: src/authorization/delegated.ts:42
Create an AuthorizationProvider from a plain decision function.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
DelegatedAuthorizationOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { delegatedAuthorization } from "@xtandard/audit/authorization/delegated";
const authz = delegatedAuthorization({ authorize: ({ principal, resource }) => { const tenants = (principal?.metadata as { tenants?: string[] } | undefined)?.tenants; const tenant = "tenant" in resource ? resource.tenant : undefined; // Cross-tenant listings (no tenant) are for staff only. return tenant ? tenants?.includes(tenant) === true : principal?.roles?.includes("staff") === true; },});