Skip to content

requireTenant

requireTenant(purpose, source?): string

Defined in: packages/ddd-core/application/tenant-resolver.ts:67

Returns the tenant for a security-sensitive operation, or fails closed.

An explicit string always wins, even an empty one. An object uses its tenantId; without one, or when source is omitted, the tenant of the registered setTenantResolver resolver applies. Nothing resolved, or an empty tenant, throws MissingTenantContextError: keys for caches, idempotency and rate limits must never collapse several tenants into one shared namespace.

string

What the tenant is for, named in the error.

TenantSource

The explicit tenant; omitted, the resolver’s tenant.

string

The non-empty tenant id.

When no tenant can be resolved.

// The tenant of the running unit of work, through the resolver:
const tenantId = requireTenant('access token issuance');
// A key factory that receives a request or job context:
const keyTenant = requireTenant('users.create idempotency key', ctx);