Skip to content

Conversation

@Ray0907
Copy link

@Ray0907 Ray0907 commented Dec 2, 2025

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc
    annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and
    libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing
    functionality to change)

πŸ“š Description

Adds a unified error handling system for both local and authjs
providers.

Problem

Previously, error handling was inconsistent across the module:

  • Some errors were silently ignored
  • Some threw exceptions
  • Some returned undefined
  • Error formats varied between providers

Solution

  • Add AuthError class with structured error data (code, message,
    statusCode, recoverable, timestamp)
  • Add error, setError, clearError to useAuth() and useAuthState()
    return values
  • Add createAuthError factory functions for common error types
  • Add toAuthError() converter for normalizing any error to AuthError
  • Export error utilities via auto-imports and #auth module

Usage

const { signIn, error, clearError } = useAuth() await signIn(credentials) if (error.value) { console.log(error.value.code) // 'INVALID_CREDENTIALS' console.log(error.value.message) // 'Invalid username or password' if (error.value.recoverable) { // show retry button } } Available Error Codes INVALID_CREDENTIALS | INVALID_PROVIDER | TOKEN_EXPIRED | TOKEN_INVALID | TOKEN_MISSING | TOKEN_PARSE_ERROR | SESSION_EXPIRED | SESSION_FETCH_ERROR | NETWORK_ERROR | TIMEOUT | SERVER_ERROR | ENDPOINT_DISABLED | UNKNOWN_ERROR πŸ“ Checklist - I have linked an issue or discussion. - I have added tests (if possible). - I have updated the documentation accordingly. ---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant