NestAuthModule
Full reference for `NestAuthModule.forRoot()` and `forRootAsync()`.
NestAuthModule is the entry point for the entire library. You import it once in your AppModule and pass an IAuthModuleOptions config object.
Synchronous form
Async form
For when your config depends on something injectable (e.g. a ConfigService):
You can also use useClass or useExisting patterns — see IAuthModuleAsyncOptions.
Top-level options
Required
| Option | Type | Notes |
|---|---|---|
appName | string | Used in TOTP issuer, audit events, and error messages |
Core
| Option | Type | Default | Notes |
|---|---|---|---|
isGlobal | boolean | false | Marks the module as global so you don't need to re-import it in every feature module |
enableAutoRefresh | boolean | true | Server-side support for auto-refresh on 401 |
routePrefix | string | 'auth' | Base path segment for all auth routes (e.g. 'account' serves POST /account/login). Applied in addition to any NestJS global prefix — update your client SDK endpoints to match |
Authentication methods
Registration
collectProfileFields is metadata for the public /auth/client-config endpoint — your signup form can render itself dynamically based on the server's policy. The same endpoint also returns passwordless flags, OAuth public client/app ids, platformAccess.enabled, and accessTokenType so login/signup UIs can adapt without hardcoding.
Sessions & tokens
See Sessions & Tokens for the conceptual overview. Full options:
allowMultipleAccountsturns on logging into several accounts on one client and switching the active one (Gmail/Slack-style). The backend is already multi-session, so this only opts in the capability — it's surfaced onGET /auth/client-config({ multipleAccounts: { enabled } }) and, in cookie mode, switches the server to per-account cookies + an active-account selector. See the Multi-account login & switching recipe.
MFA
See MFA.
Multi-tenancy
See Multi-Tenancy.
Authorization
Password & OTP
Force password change
The mustChangePassword flag on a user is always surfaced (login response + /auth/me) and cleared on a successful password change. Set enforce: true to additionally hard-block at the guard: a user with the flag set is rejected with 403 MUST_CHANGE_PASSWORD on every guarded route except change-password, logout, the current-user/session endpoints, and the MFA/verification routes (so a 2FA user can still finish signing in and reach the change-password screen). Exempt your own routes with @SkipMustChangePassword().
Hooks
Every config-time hook is on the Hooks Reference page. The high-level groupings:
Audit
Admin console
See Admin Console.
Debug
See Logging & Debugging.
Related
- Setup Checklist — boot-time wiring around the module.
- Hooks Reference — every hook with execution-order timeline.
- API Reference: Types — auto-generated
IAuthModuleOptionsdefinition.