@auth0/nextjs-auth0
Version:
Auth0 Next.js SDK
187 lines (186 loc) • 7.12 kB
JavaScript
import { SdkError } from "./sdk-error.js";
/**
* Errors that come from Auth0 in the `redirect_uri` callback may contain reflected user input via the OpenID Connect `error` and `error_description` query parameter.
* You should **not** render the error `message`, or `error` and `error_description` properties without properly escaping them first.
*/
export class OAuth2Error extends SdkError {
constructor({ code, message }) {
super(message ??
"An error occurred while interacting with the authorization server.");
this.name = "OAuth2Error";
this.code = code;
}
}
export class DiscoveryError extends SdkError {
constructor(message) {
super(message ?? "Discovery failed for the OpenID Connect configuration.");
this.code = "discovery_error";
this.name = "DiscoveryError";
}
}
export class MissingStateError extends SdkError {
constructor(message) {
super(message ?? "The state parameter is missing.");
this.code = "missing_state";
this.name = "MissingStateError";
}
}
export class InvalidStateError extends SdkError {
constructor(message) {
super(message ?? "The state parameter is invalid.");
this.code = "invalid_state";
this.name = "InvalidStateError";
}
}
export class InvalidConfigurationError extends SdkError {
constructor(message) {
super(message ?? "The configuration is invalid.");
this.code = "invalid_configuration";
this.name = "InvalidConfigurationError";
}
}
export class AuthorizationError extends SdkError {
constructor({ cause, message }) {
super(message ?? "An error occurred during the authorization flow.");
this.code = "authorization_error";
this.cause = cause;
this.name = "AuthorizationError";
}
}
export class AuthorizationCodeGrantRequestError extends SdkError {
constructor(message) {
super(message ??
"An error occurred while preparing or performing the authorization code grant request.");
this.code = "authorization_code_grant_request_error";
this.name = "AuthorizationCodeGrantRequestError";
}
}
export class AuthorizationCodeGrantError extends SdkError {
constructor({ cause, message }) {
super(message ??
"An error occurred while trying to exchange the authorization code.");
this.code = "authorization_code_grant_error";
this.cause = cause;
this.name = "AuthorizationCodeGrantError";
}
}
export class BackchannelLogoutError extends SdkError {
constructor(message) {
super(message ??
"An error occurred while completing the backchannel logout request.");
this.code = "backchannel_logout_error";
this.name = "BackchannelLogoutError";
}
}
export class BackchannelAuthenticationNotSupportedError extends SdkError {
constructor() {
super("The authorization server does not support backchannel authentication. Learn how to enable it here: https://auth0.com/docs/get-started/applications/configure-client-initiated-backchannel-authentication");
this.code = "backchannel_authentication_not_supported_error";
this.name = "BackchannelAuthenticationNotSupportedError";
}
}
export class BackchannelAuthenticationError extends SdkError {
constructor({ cause }) {
super("There was an error when trying to use Client-Initiated Backchannel Authentication.");
this.code = "backchannel_authentication_error";
this.cause = cause;
this.name = "BackchannelAuthenticationError";
}
}
export var AccessTokenErrorCode;
(function (AccessTokenErrorCode) {
AccessTokenErrorCode["MISSING_SESSION"] = "missing_session";
AccessTokenErrorCode["MISSING_REFRESH_TOKEN"] = "missing_refresh_token";
AccessTokenErrorCode["FAILED_TO_REFRESH_TOKEN"] = "failed_to_refresh_token";
})(AccessTokenErrorCode || (AccessTokenErrorCode = {}));
export class AccessTokenError extends SdkError {
constructor(code, message, cause) {
super(message);
this.name = "AccessTokenError";
this.code = code;
this.cause = cause;
}
}
/**
* Enum representing error codes related to access tokens for connections.
*/
export var AccessTokenForConnectionErrorCode;
(function (AccessTokenForConnectionErrorCode) {
/**
* The session is missing.
*/
AccessTokenForConnectionErrorCode["MISSING_SESSION"] = "missing_session";
/**
* The refresh token is missing.
*/
AccessTokenForConnectionErrorCode["MISSING_REFRESH_TOKEN"] = "missing_refresh_token";
/**
* Failed to exchange the refresh token.
*/
AccessTokenForConnectionErrorCode["FAILED_TO_EXCHANGE"] = "failed_to_exchange_refresh_token";
})(AccessTokenForConnectionErrorCode || (AccessTokenForConnectionErrorCode = {}));
/**
* Error class representing an access token for connection error.
* Extends the `SdkError` class.
*/
export class AccessTokenForConnectionError extends SdkError {
/**
* Constructs a new `AccessTokenForConnectionError` instance.
*
* @param code - The error code.
* @param message - The error message.
* @param cause - The OAuth2 cause of the error.
*/
constructor(code, message, cause) {
super(message);
this.name = "AccessTokenForConnectionError";
this.code = code;
this.cause = cause;
}
}
/**
* Error codes for Custom Token Exchange errors.
*/
export var CustomTokenExchangeErrorCode;
(function (CustomTokenExchangeErrorCode) {
/**
* The subject_token is missing or empty.
*/
CustomTokenExchangeErrorCode["MISSING_SUBJECT_TOKEN"] = "missing_subject_token";
/**
* The subject_token_type is not a valid URI, wrong length, or uses a reserved namespace.
*/
CustomTokenExchangeErrorCode["INVALID_SUBJECT_TOKEN_TYPE"] = "invalid_subject_token_type";
/**
* The actor_token was provided without actor_token_type.
*/
CustomTokenExchangeErrorCode["MISSING_ACTOR_TOKEN_TYPE"] = "missing_actor_token_type";
/**
* The token exchange request failed.
*/
CustomTokenExchangeErrorCode["EXCHANGE_FAILED"] = "exchange_failed";
})(CustomTokenExchangeErrorCode || (CustomTokenExchangeErrorCode = {}));
/**
* Error class representing a Custom Token Exchange error.
* Extends the `SdkError` class.
*
* This error is thrown when a Custom Token Exchange operation fails,
* such as validation errors or server-side token exchange failures.
*
* @see {@link https://auth0.com/docs/authenticate/custom-token-exchange Auth0 Custom Token Exchange Documentation}
*/
export class CustomTokenExchangeError extends SdkError {
/**
* Constructs a new `CustomTokenExchangeError` instance.
*
* @param code - The error code.
* @param message - The error message.
* @param cause - The OAuth2 cause of the error.
*/
constructor(code, message, cause) {
super(message);
this.name = "CustomTokenExchangeError";
this.code = code;
this.cause = cause;
}
}