feat(auth): improve error messages for expired sessions, invalid credentials, and network issues (PULSE-25) #2

Merged
uz1mani merged 1 commits from staging into main 2026-02-03 18:35:47 +00:00
uz1mani commented 2026-02-03 18:35:34 +00:00 (Migrated from github.com)

Summary

This PR standardizes authentication and API error handling across the application. It replaces generic or raw server error messages with safe, actionable copy (e.g., "Session expired, please sign in again" vs "Network error, please try again") to improve UX and prevent sensitive detail exposure.

Changes

  • Centralized Error Copy: Added lib/utils/authErrors.ts to map status codes and error types to user-facing messages.
  • API Client Improvements:
    • Added a 30s timeout to all requests.
    • Automatically maps 401/403/5xx and network/timeout errors to the standardized messages.
    • Ensures token refresh failures trigger the correct "Session expired" message.
  • Auth Callback:
    • Now distinguishes between invalid credentials (re-login) and network errors (retry).
    • Added a "Try again" button for network failures.
  • Server Actions: Updated exchangeAuthCode and setSessionAction to return structured error codes (expired, invalid, network) instead of raw error strings.
  • UI Consistency: Updated error toasts across Dashboard, Site Settings, and Onboarding to use the new getAuthErrorMessage helper.

Testing

  • Verified that 401 responses trigger "Session expired".
  • Verified that 403 responses trigger "Invalid credentials".
  • Verified that network failures (simulated) trigger "Network error" and show a retry option in the auth callback.
## Summary This PR standardizes authentication and API error handling across the application. It replaces generic or raw server error messages with safe, actionable copy (e.g., "Session expired, please sign in again" vs "Network error, please try again") to improve UX and prevent sensitive detail exposure. ## Changes - **Centralized Error Copy**: Added `lib/utils/authErrors.ts` to map status codes and error types to user-facing messages. - **API Client Improvements**: - Added a 30s timeout to all requests. - Automatically maps 401/403/5xx and network/timeout errors to the standardized messages. - Ensures token refresh failures trigger the correct "Session expired" message. - **Auth Callback**: - Now distinguishes between invalid credentials (re-login) and network errors (retry). - Added a "Try again" button for network failures. - **Server Actions**: Updated `exchangeAuthCode` and `setSessionAction` to return structured error codes (`expired`, `invalid`, `network`) instead of raw error strings. - **UI Consistency**: Updated error toasts across Dashboard, Site Settings, and Onboarding to use the new `getAuthErrorMessage` helper. ## Testing - Verified that 401 responses trigger "Session expired". - Verified that 403 responses trigger "Invalid credentials". - Verified that network failures (simulated) trigger "Network error" and show a retry option in the auth callback.
Sign in to join this conversation.
No description provided.