Multi-tenancy
Multi-tenancy
How NShop hosts many stores from one codebase, safely.
NShop is multi-tenant from the ground up. One install runs many stores; each is isolated in catalog, orders, branding, payouts, and team — but all share the same customer identity.
Three layers of isolation
Tenant safety is enforced by three independent layers. None of them trust each other; a bug in one is caught by the next.
- Request-time tenant resolution — the middleware parses the
subdomain off
Hostand writes anx-tenantheader on every request. Server code reads that header throughgetTenantSlug()— never the raw host. - Auth custom claims — Firebase Auth users carry a
tenantIdclaim (for tenant admins) or asuperadmin: trueclaim. Every mutating API route re-verifies the claim against the request's tenant. - Firestore security rules — the data model is locked at the database. Even if a route forgot to check, the rule would refuse the write.
Each layer alone would be enough most of the time. Together, a slip in one is caught by the others.
What's in this section
- Tenants and domains — subdomains, custom domains, tenant resolution.
- Roles — customer, tenant admin, superadmin.
- Isolation — exactly which data is shared and which isn't.
- Superadmin — the global, read- only operator role.