Skip to content

runWithTenant

runWithTenant<T>(tenantId, fn): T

Defined in: tenant-scope.ts:26

Runs fn with tenantId as the current tenant for everything it calls, synchronously or asynchronously.

Use it where work enters the application, such as HTTP middleware or a queue job, or to change the tenant for part of a handler. A pipeline dispatched inside fn takes this tenant, and nested dispatches inherit it. A nested call replaces the tenant for its own callback only, and undefined runs fn with no tenant.

T

string | undefined

The tenant for the callback, or undefined for none.

() => T

The work to run.

T

What fn returns (its promise, for an async callback).

await runWithTenant(job.data.tenant, () => processBatch(job.data));