| import { WeakPasswordReasons } from './types' |
| import { ErrorCode } from './error-codes' |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthError extends Error { |
| |
| |
| |
| |
| |
| |
| code: ErrorCode | (string & {}) | undefined |
|
|
| |
| status: number | undefined |
|
|
| protected __isAuthError = true |
|
|
| constructor(message: string, status?: number, code?: string) { |
| super(message) |
| this.name = 'AuthError' |
| this.status = status |
| this.code = code |
| } |
|
|
| toJSON(): { |
| name: string |
| message: string |
| status: number | undefined |
| code: ErrorCode | (string & {}) | undefined |
| } { |
| return { |
| name: this.name, |
| message: this.message, |
| status: this.status, |
| code: this.code, |
| } |
| } |
| } |
|
|
| export function isAuthError(error: unknown): error is AuthError { |
| return typeof error === 'object' && error !== null && '__isAuthError' in error |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthApiError extends AuthError { |
| status: number |
|
|
| constructor(message: string, status: number, code: string | undefined) { |
| super(message, status, code) |
| this.name = 'AuthApiError' |
| this.status = status |
| this.code = code |
| } |
| } |
|
|
| export function isAuthApiError(error: unknown): error is AuthApiError { |
| return isAuthError(error) && error.name === 'AuthApiError' |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthUnknownError extends AuthError { |
| originalError: unknown |
|
|
| constructor(message: string, originalError: unknown) { |
| super(message) |
| this.name = 'AuthUnknownError' |
| this.originalError = originalError |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class CustomAuthError extends AuthError { |
| name: string |
| status: number |
|
|
| constructor(message: string, name: string, status: number, code: string | undefined) { |
| super(message, status, code) |
| this.name = name |
| this.status = status |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthSessionMissingError extends CustomAuthError { |
| constructor() { |
| super('Auth session missing!', 'AuthSessionMissingError', 400, undefined) |
| } |
| } |
|
|
| export function isAuthSessionMissingError(error: any): error is AuthSessionMissingError { |
| return isAuthError(error) && error.name === 'AuthSessionMissingError' |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthInvalidTokenResponseError extends CustomAuthError { |
| constructor() { |
| super('Auth session or user missing', 'AuthInvalidTokenResponseError', 500, undefined) |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthInvalidCredentialsError extends CustomAuthError { |
| constructor(message: string) { |
| super(message, 'AuthInvalidCredentialsError', 400, undefined) |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthImplicitGrantRedirectError extends CustomAuthError { |
| details: { error: string; code: string } | null = null |
| constructor(message: string, details: { error: string; code: string } | null = null) { |
| super(message, 'AuthImplicitGrantRedirectError', 500, undefined) |
| this.details = details |
| } |
|
|
| toJSON(): { |
| name: string |
| message: string |
| status: number | undefined |
| code: ErrorCode | (string & {}) | undefined |
| details: { error: string; code: string } | null |
| } { |
| return { |
| ...super.toJSON(), |
| details: this.details, |
| } |
| } |
| } |
|
|
| export function isAuthImplicitGrantRedirectError( |
| error: any |
| ): error is AuthImplicitGrantRedirectError { |
| return isAuthError(error) && error.name === 'AuthImplicitGrantRedirectError' |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthPKCEGrantCodeExchangeError extends CustomAuthError { |
| details: { error: string; code: string } | null = null |
|
|
| constructor(message: string, details: { error: string; code: string } | null = null) { |
| super(message, 'AuthPKCEGrantCodeExchangeError', 500, undefined) |
| this.details = details |
| } |
|
|
| toJSON(): { |
| name: string |
| message: string |
| status: number | undefined |
| code: ErrorCode | (string & {}) | undefined |
| details: { error: string; code: string } | null |
| } { |
| return { |
| ...super.toJSON(), |
| details: this.details, |
| } |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthPKCECodeVerifierMissingError extends CustomAuthError { |
| constructor() { |
| super( |
| 'PKCE code verifier not found in storage. ' + |
| 'This can happen if the auth flow was initiated in a different browser or device, ' + |
| 'or if the storage was cleared. For SSR frameworks (Next.js, SvelteKit, etc.), ' + |
| 'use @supabase/ssr on both the server and client to store the code verifier in cookies.', |
| 'AuthPKCECodeVerifierMissingError', |
| 400, |
| 'pkce_code_verifier_not_found' |
| ) |
| } |
| } |
|
|
| export function isAuthPKCECodeVerifierMissingError( |
| error: unknown |
| ): error is AuthPKCECodeVerifierMissingError { |
| return isAuthError(error) && error.name === 'AuthPKCECodeVerifierMissingError' |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthRetryableFetchError extends CustomAuthError { |
| constructor(message: string, status: number) { |
| super(message, 'AuthRetryableFetchError', status, undefined) |
| } |
| } |
|
|
| export function isAuthRetryableFetchError(error: unknown): error is AuthRetryableFetchError { |
| return isAuthError(error) && error.name === 'AuthRetryableFetchError' |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthRefreshDiscardedError extends CustomAuthError { |
| constructor( |
| message = 'Refresh result discarded: session state changed mid-flight (e.g., concurrent signOut)' |
| ) { |
| super(message, 'AuthRefreshDiscardedError', 409, undefined) |
| } |
| } |
|
|
| export function isAuthRefreshDiscardedError(error: unknown): error is AuthRefreshDiscardedError { |
| return isAuthError(error) && error.name === 'AuthRefreshDiscardedError' |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthWeakPasswordError extends CustomAuthError { |
| |
| |
| |
| reasons: WeakPasswordReasons[] |
|
|
| constructor(message: string, status: number, reasons: WeakPasswordReasons[]) { |
| super(message, 'AuthWeakPasswordError', status, 'weak_password') |
|
|
| this.reasons = reasons |
| } |
|
|
| toJSON(): { |
| name: string |
| message: string |
| status: number | undefined |
| code: ErrorCode | (string & {}) | undefined |
| reasons: WeakPasswordReasons[] |
| } { |
| return { |
| ...super.toJSON(), |
| reasons: this.reasons, |
| } |
| } |
| } |
|
|
| export function isAuthWeakPasswordError(error: unknown): error is AuthWeakPasswordError { |
| return isAuthError(error) && error.name === 'AuthWeakPasswordError' |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export class AuthInvalidJwtError extends CustomAuthError { |
| constructor(message: string) { |
| super(message, 'AuthInvalidJwtError', 400, 'invalid_jwt') |
| } |
| } |
|
|