nest-tenant
Multi-tenant library for NestJS: RLS and schema-per-tenant isolation, AsyncLocalStorage context, ORM adapters, CLI.
At a glance
Provide drop-in multi-tenancy for NestJS applications with multiple isolation strategies, automatic context propagation, and ORM integration.
NestJS developers building multi-tenant SaaS applications who want configurable tenant isolation without building it from scratch.
- Row-Level Security (RLS) tenant isolation
- Schema-per-tenant isolation strategy
- AsyncLocalStorage-based context propagation
Context
Multi-tenancy is a solved problem, but implementing it correctly requires handling context propagation, database isolation, and ORM integration. Most NestJS projects implement this ad-hoc, leading to bugs and security gaps.
The Problem
Tenant context must flow through the entire request lifecycle without manual passing. Isolation strategies vary by use case: RLS for shared schemas, separate schemas for strict isolation. ORM integrations require middleware hooks.
Approach
nest-tenant uses AsyncLocalStorage to propagate tenant context automatically. Middleware extracts tenant identity from requests and sets context. ORM adapters apply isolation policies transparently. The library is published on npm for easy adoption.