The Auth0 Next.js SDK uses a hierarchical error class system for consistent error handling. All errors extend from the baseDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/auth0/nextjs-auth0/llms.txt
Use this file to discover all available pages before exploring further.
SdkError class and include a code property for programmatic error identification.
Error Handling Pattern
Use error codes, notinstanceof:
Base Error Class
SdkError
Base class for all SDK errors.code: Unique error code for programmatic identificationmessage: Human-readable error descriptionname: Error class name
OAuth and Authorization Errors
OAuth2Error
Errors from Auth0 in theredirect_uri callback that may contain reflected user input.
code: OAuth error code from Auth0message: Error description
DiscoveryError
Code:discovery_error
Thrown when OpenID Connect discovery fails.
MissingStateError
Code:missing_state
The state parameter is missing from the callback.
InvalidStateError
Code:invalid_state
The state parameter in the callback is invalid or doesn’t match.
InvalidConfigurationError
Code:invalid_configuration
The SDK configuration is invalid or incomplete.
AuthorizationError
Code:authorization_error
An error occurred during the authorization flow.
Properties:
cause: The underlyingOAuth2Error
AuthorizationCodeGrantRequestError
Code:authorization_code_grant_request_error
Error occurred while preparing or performing the authorization code grant request.
AuthorizationCodeGrantError
Code:authorization_code_grant_error
Error occurred while exchanging the authorization code for tokens.
Properties:
cause: The underlyingOAuth2Error
BackchannelLogoutError
Code:backchannel_logout_error
Error occurred during backchannel logout request processing.
BackchannelAuthenticationNotSupportedError
Code:backchannel_authentication_not_supported_error
The authorization server does not support backchannel authentication.
BackchannelAuthenticationError
Code:backchannel_authentication_error
Error when using Client-Initiated Backchannel Authentication.
Properties:
cause: The underlyingOAuth2Error(optional)
Access Token Errors
AccessTokenError
Errors related to access token retrieval or refresh. Error codes:| Code | Value | Description |
|---|---|---|
MISSING_SESSION | missing_session | User session not found |
MISSING_REFRESH_TOKEN | missing_refresh_token | No refresh token available for refresh |
FAILED_TO_REFRESH_TOKEN | failed_to_refresh_token | Token refresh request failed |
code: Error code fromAccessTokenErrorCodecause: The underlyingOAuth2Error(optional)
AccessTokenForConnectionError
Errors related to access tokens for specific connections. Error codes:| Code | Value | Description |
|---|---|---|
MISSING_SESSION | missing_session | User session not found |
MISSING_REFRESH_TOKEN | missing_refresh_token | No refresh token for connection |
FAILED_TO_EXCHANGE | failed_to_exchange_refresh_token | Failed to exchange refresh token |
code: Error code fromAccessTokenForConnectionErrorCodecause: The underlyingOAuth2Error(optional)
CustomTokenExchangeError
Errors during custom token exchange operations. Error codes:| Code | Value | Description |
|---|---|---|
MISSING_SUBJECT_TOKEN | missing_subject_token | Subject token is missing or empty |
INVALID_SUBJECT_TOKEN_TYPE | invalid_subject_token_type | Invalid subject token type URI |
MISSING_ACTOR_TOKEN_TYPE | missing_actor_token_type | Actor token provided without type |
EXCHANGE_FAILED | exchange_failed | Token exchange request failed |
code: Error code fromCustomTokenExchangeErrorCodecause: The underlyingOAuth2Error(optional)
DPoP Errors
DPoPError
Errors during DPoP (Demonstrating Proof-of-Possession) operations. Error codes:| Code | Value | Description |
|---|---|---|
DPOP_JKT_CALCULATION_FAILED | dpop_jkt_calculation_failed | Failed to calculate JWK thumbprint |
DPOP_KEY_EXPORT_FAILED | dpop_key_export_failed | Failed to export public key to JWK |
DPOP_CONFIGURATION_ERROR | dpop_configuration_error | Invalid DPoP configuration |
code: Error code fromDPoPErrorCodecause: The underlying error (optional)
MFA Errors
MfaRequiredError
Code:mfa_required
Thrown when getAccessToken() requires MFA step-up authentication.
code:mfa_requirederror:mfa_requirederror_description: Error description from Auth0mfa_token: Encrypted MFA token for use with MFA API methodsmfa_requirements: Available challenge/enrollment methods (optional)cause: Underlying error (optional)
InvalidRequestError
Code:invalid_request
Request validation failed (missing or invalid parameters).
MfaGetAuthenticatorsError
Failed to list MFA authenticators.error: Auth0 error codeerror_description: Error descriptioncause: Original Auth0 API error response (optional)
MfaChallengeError
Failed to initiate an MFA challenge.error: Auth0 error codeerror_description: Error descriptioncause: Original Auth0 API error response (optional)
MfaVerifyError
MFA verification failed.error: Auth0 error codeerror_description: Error descriptioncause: Original Auth0 API error response (optional)
MfaEnrollmentError
MFA enrollment failed.error: Auth0 error codeerror_description: Error descriptioncause: Original Auth0 API error response (optional)
MfaNoAvailableFactorsError
Code:mfa_no_available_factors
No MFA factors are available for challenge. This is an SDK-generated error with no Auth0 API equivalent.
MfaTokenExpiredError
Code:mfa_token_expired
The MFA token has expired. The user must restart the MFA flow.
MfaTokenInvalidError
Code:mfa_token_invalid
The encrypted MFA token is invalid or has been tampered with.
My Account API Errors
MyAccountApiError
Code:my_account_api_error
Error from Auth0’s My Account API.
code:my_account_api_errortype: Error typetitle: Error titledetail: Error detailstatus: HTTP status codevalidationErrors: Array of validation errors (optional)
ConnectAccountError
Error during account linking flow. Error codes:| Code | Value | Description |
|---|---|---|
MISSING_SESSION | missing_session | User session not found |
FAILED_TO_INITIATE | failed_to_initiate | Failed to initiate connect flow |
FAILED_TO_COMPLETE | failed_to_complete | Failed to complete connect flow |
code: Error code fromConnectAccountErrorCodescause: The underlyingMyAccountApiError(optional)
Error Response Format
Many errors implementtoJSON() for consistent HTTP response formatting:
Importing Errors
Best Practices
Use error codes, not instanceof
Use error codes, not instanceof
Error codes are more reliable and work across module boundaries.
Always sanitize OAuth2Error messages
Always sanitize OAuth2Error messages
OAuth errors may contain user input. Never render them directly.
Check error.cause for details
Check error.cause for details
Many errors include a
cause property with the underlying error.Use toJSON() for API responses
Use toJSON() for API responses
Errors with
toJSON() are designed for HTTP responses.