Skip to content

delegatedAuthorization

function delegatedAuthorization(options): AuthorizationProvider;

Defined in: src/authorization/delegated.ts:43

Create an AuthorizationProvider from a plain decision function.

Parameter Type
options DelegatedAuthorizationOptions

AuthorizationProvider

import { delegatedAuthorization } from "@xtandard/entitlements/authorization/delegated";
const authz = delegatedAuthorization({
// Support staff may only touch the customers of their own region.
authorize: ({ principal, resource }) =>
!("customer" in resource) ||
resource.customer === undefined ||
(principal?.metadata as { customers?: string[] } | undefined)?.customers?.includes(
resource.customer,
) === true,
});