Nest Authbeta

Error Codes

Every error code the library can return.

When AuthExceptionFilter is registered, the library's exceptions become structured responses:

{
  "statusCode": 401,
  "errorCode": "INVALID_CREDENTIALS",
  "message": "Email or password is incorrect"
}

The errorCode field is what your frontend should branch on — never the human-readable message.

Auth

CodeStatusMeaning
EMAIL_ALREADY_EXISTS409Signup with an email that's already registered
PHONE_ALREADY_EXISTS409Signup with a phone that's already registered
INVALID_CREDENTIALS401Wrong email/password
ACCOUNT_INACTIVE403isActive: false (admin-disabled or self-deactivated)
ACCOUNT_SUSPENDED403Suspended via metadata flag (compliance / fraud)
EMAIL_NOT_VERIFIED403Login policy requires email verification
PHONE_NOT_VERIFIED403Login policy requires phone verification
INVALID_REFRESH_TOKEN401Refresh token expired or revoked
TENANT_REQUIRED400Multi-tenant mode requires tenantId and the request didn't carry one

MFA

CodeStatusMeaning
MFA_REQUIRED401Login succeeded but MFA must be completed before access tokens are issued
MFA_INVALID_CODE401Wrong code
MFA_CODE_EXPIRED401Code is past its expiry
MFA_NOT_ENABLED400User tried to verify MFA they don't have configured
MFA_ALREADY_ENABLED400Toggle-on against an already-enabled account
MFA_RECOVERY_INVALID401Recovery code rejected
TOTP_INVALID_SETUP400Setup code didn't match the secret

Sessions

CodeStatusMeaning
SESSION_NOT_FOUND401Session row missing — usually means revoked
SESSION_EXPIRED401Session past its expiry
MAX_SESSIONS_REACHED400Login would exceed maxSessionsPerUser (only fires if eviction is disabled)

Guards / authorization

CodeStatusMeaning
INVALID_AUTH_HEADER401Missing or malformed Authorization header
INSUFFICIENT_ROLES403@NestAuthRoles constraint not satisfied
INSUFFICIENT_PERMISSIONS403@NestAuthPermissions constraint not satisfied
IP_BLOCKED403guards.beforeAuth rejected with this reason

API keys

CodeStatusMeaning
INVALID_API_KEY401Key not found, expired, or deactivated
API_KEY_FORMAT_INVALID401Header format isn't <public>:<private>

Validation

CodeStatusMeaning
EMAIL_FORMAT_INVALID400Doesn't match the email regex
PHONE_FORMAT_INVALID400Not E.164
WEAK_PASSWORD400Fired only when a beforeSignup hook throws this
MISSING_REQUIRED_FIELD400DTO validation fail (class-validator)

OTP

CodeStatusMeaning
OTP_INVALID401Code rejected
OTP_EXPIRED401Code past codeExpiresIn
OTP_ALREADY_USED401Code is one-shot and was already redeemed

Tenants

CodeStatusMeaning
TENANT_NOT_FOUND404Tenant id/slug doesn't exist
TENANT_ALREADY_EXISTS409Slug collision on create
TENANT_INVALID400Slug failed validation

Customizing

Use the errorHandler(error, context) hook to transform errors per flow — see the per-flow error transform recipe.

On this page