class JwtResolver
implements ITenantResolver

Resolves the tenant id from a claim in an unverified JWT payload.

Security note: This resolver uses unverified decode — tenant identity is taken from an unsigned token claim. An application using this without auth middleware must understand a client could spoof the tenant claim.

Examples

Example 1

const resolver = new JwtResolver({ claim: 'tenant_id' });
const result = await resolver.resolve(request);
// => some({ id: 'acme' })  when payload has tenant_id='acme'

Constructors

JwtResolver(options:
JwtResolverOptions
& { decode: (token: string) => Record<string, unknown> | null; }
)

Methods

resolve(request: IRequest): Promise<Option<ITenant>>

Resolve the tenant id from the configured JWT claim.

Usage

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