Skip to content

requireEntitlement

function requireEntitlement<C, Ctx>(
engine,
feature,
options
): (ctx) => Promise<Response | undefined>;

Defined in: src/adapters/elysia-shared.ts:99

An Elysia beforeHandle guard (works on 1.x and 2.x): answers 402 / 403 JSON for denials, 401 without a customer; for an allowed request it sets ctx.entitlement and lets the handler run.

app.post("/export", ({ entitlement }) => ({ ok: true }), {
beforeHandle: requireEntitlement(ent, "export_pdf", {
customer: ({ request }) => request.headers.get("x-org-id"),
}),
});
Type Parameter Default type
C extends AnyCatalog -
Ctx extends ElysiaGuardContext ElysiaGuardContext
Parameter Type
engine Entitlements<C>
feature FeatureKey<C>
options RequireEntitlementOptions<Ctx>

(ctx) => Promise<Response | undefined>