function tenantMiddleware
tenantMiddleware(arg_0: TenantMiddlewareOptions): MiddlewareFunction

Factory that creates a middleware function resolving the tenant and attaching it to ctx.request.tenant.

On successful resolution: calls next(). When required: true and no tenant resolves: short-circuits with a 400 (or rejectionStatus) without calling next(), written through the error responder seam (respondWithError in @setu-ts/common) so it answers in the application's configured format when errorHandler is registered, and in the no-handler fallback shape { error, detail? } otherwise. When required: false and no tenant resolves: proceeds with ctx.request.tenant === undefined.

A throwing resolver is caught, warned (when logger is present), treated as none(), and the chain continues to the next resolver.

Parameters

arg_0: TenantMiddlewareOptions

Return Type

MiddlewareFunction

Usage

import { tenantMiddleware } from "multi-tenancy-plugin/src/index.ts";