Platform-admin portal
A "manage the entire platform" portal — full nest-auth users with a cross-tenant super-admin role, origin-locked and optionally MFA-gated.
You need an internal portal where your own staff manage all tenants and the whole platform — and unlike the minimal admin console, these admins want the full nest-auth feature set: social login, MFA, passwordless, RBAC.
Don't build a second auth system. Make platform admins normal NestAuthUsers that hold a
platform-level role granted via the first-class PlatformAccess
(cross-tenant, resolved on every login) — then gate the portal on that role, origin-lock it,
and optionally require MFA.
A complete, tested reference lives in the example app at apps/example-nest/src/platform/
(and test/platform-admin.e2e-spec.ts).
1. Configure a guard namespace + platform access
validate returning false for normal tenant logins means tenant RBAC is completely
unaffected — only requests coming through the portal get platform access.
2. Seed the first platform admin (chicken-and-egg)
Idempotent boot seeder: create the platform role, the first admin user, and grant it via
PlatformAccess. In production, prefer a migration or a one-time secret over env defaults.
3. The cross-tenant management controller
Every route requires the platform role under the platform guard. Because platform roles are
tenantId-independent, queries here are intentionally not tenant-filtered.
No privilege escalation: a tenant user can never reach grant-admin (the platform-role guard
blocks them), so only an existing platform admin can create another.
4. Logging in through the portal
The portal sends the origin-lock header on login. Add it to CORS so the browser can:
The role is baked into the session at login, so subsequent /platform/* calls just send the
bearer token — no header needed on every request.
5. Optional: require MFA for platform admins
Because platform admins are real users, "require MFA" just reuses the MFA flow. A tiny guard, read per-request so you can flip the policy without a rebuild:
Once the admin enrols TOTP, every portal login goes through the MFA challenge before the portal opens.
Security boundaries (all tested)
| Scenario | Result |
|---|---|
Tenant user → /platform/* | 403 (no platform role) |
Super-admin logs in without the portal header → /platform/* | 403 (origin-lock) |
| Non-platform user logs in with the portal header | 403 ACCESS_DENIED |
Tenant user → POST /platform/grant-admin | 403 (no escalation) |
PLATFORM_REQUIRE_MFA=true, admin without MFA | 403 PLATFORM_MFA_REQUIRED |
Related
- User Access & Platform Access — the
PlatformAccessmodel +validateorigin-lock - Multi-platform login with guards — guard namespaces per portal
- RBAC · Multi-tenancy · Admin console