MFA & tenancy
Two-factor login, TOTP setup, recovery codes, and tenant switching via `useNestAuth()`.
This page covers multi-factor authentication and multi-tenant switching. As everywhere in the SDK, the actions come from useNestAuth() and are async.
MFA-gated login
When an account has MFA enabled, login(...) resolves with a response whose isRequiresMfa is true instead of completing the session. Send a code, then verify it to finish:
send2fa accepts an optional method — 'email' or 'phone'. verify2fa takes { otp, method?, trustDevice? }; pass trustDevice: true to skip the second factor on this device next time:
TOTP (authenticator app) setup
Let a signed-in user enroll an authenticator app. setupTotp() returns the enrollment data (such as the secret / otpauth URI to render as a QR code); after the user scans it and enters the first code, confirm with verifyTotpSetup:
verifyTotpSetup(dto)takes the DTO your backend expects for confirming enrollment (typically the first code from the authenticator app).
MFA status & devices
Inspect and manage a user's MFA configuration:
Recovery codes
Generate a backup recovery code, and use one to reset MFA if the user loses their device:
Switching tenants
For multi-tenant apps, switch the active tenant on the existing client (don't remount the provider). switchTenant re-scopes the session to a new tenant:
You can also read or set the tenant id directly on the client without performing a switch round-trip:
login(...) also accepts a tenantId? so you can target a specific tenant at sign-in time — see Authentication.
Related
- Authentication — login, signup, password flows.
- Hooks & guards — gate screens by role and permission.