Skip to main content
The Auth0 Next.js SDK uses a hierarchical error class system for consistent error handling. All errors extend from the base SdkError class and include a code property for programmatic error identification.

Error Handling Pattern

Use error codes, not instanceof:

Base Error Class

SdkError

Base class for all SDK errors.
Properties:
  • code: Unique error code for programmatic identification
  • message: Human-readable error description
  • name: Error class name

OAuth and Authorization Errors

OAuth2Error

Errors from Auth0 in the redirect_uri callback that may contain reflected user input.
Security: Do not render error or error_description properties without properly escaping them to prevent XSS vulnerabilities.
Properties:
  • code: OAuth error code from Auth0
  • message: 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 underlying OAuth2Error

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 underlying OAuth2Error

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 underlying OAuth2Error (optional)

Access Token Errors

AccessTokenError

Errors related to access token retrieval or refresh. Error codes:
Properties:
  • code: Error code from AccessTokenErrorCode
  • cause: The underlying OAuth2Error (optional)

AccessTokenForConnectionError

Errors related to access tokens for specific connections. Error codes:
Properties:
  • code: Error code from AccessTokenForConnectionErrorCode
  • cause: The underlying OAuth2Error (optional)

CustomTokenExchangeError

Errors during custom token exchange operations. Error codes:
Properties:
  • code: Error code from CustomTokenExchangeErrorCode
  • cause: The underlying OAuth2Error (optional)

DPoP Errors

DPoPError

Errors during DPoP (Demonstrating Proof-of-Possession) operations. Error codes:
Properties:
  • code: Error code from DPoPErrorCode
  • cause: The underlying error (optional)

MFA Errors

MfaRequiredError

Code: mfa_required Thrown when getAccessToken() requires MFA step-up authentication.
Properties:
  • code: mfa_required
  • error: mfa_required
  • error_description: Error description from Auth0
  • mfa_token: Encrypted MFA token for use with MFA API methods
  • mfa_requirements: Available challenge/enrollment methods (optional)
  • cause: Underlying error (optional)
JSON serialization:

InvalidRequestError

Code: invalid_request Request validation failed (missing or invalid parameters).

MfaGetAuthenticatorsError

Failed to list MFA authenticators.
Properties:
  • error: Auth0 error code
  • error_description: Error description
  • cause: Original Auth0 API error response (optional)

MfaChallengeError

Failed to initiate an MFA challenge.
Properties:
  • error: Auth0 error code
  • error_description: Error description
  • cause: Original Auth0 API error response (optional)

MfaVerifyError

MFA verification failed.
Properties:
  • error: Auth0 error code
  • error_description: Error description
  • cause: Original Auth0 API error response (optional)

MfaEnrollmentError

MFA enrollment failed.
Properties:
  • error: Auth0 error code
  • error_description: Error description
  • cause: 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.
Properties:
  • code: my_account_api_error
  • type: Error type
  • title: Error title
  • detail: Error detail
  • status: HTTP status code
  • validationErrors: Array of validation errors (optional)

ConnectAccountError

Error during account linking flow. Error codes:
Properties:
  • code: Error code from ConnectAccountErrorCodes
  • cause: The underlying MyAccountApiError (optional)

Error Response Format

Many errors implement toJSON() for consistent HTTP response formatting:

Importing Errors

Best Practices

Error codes are more reliable and work across module boundaries.
OAuth errors may contain user input. Never render them directly.
Many errors include a cause property with the underlying error.
Errors with toJSON() are designed for HTTP responses.