fix: Auth error handling #15

Merged
crisleo94 merged 2 commits from fix/user-auth-error-handling into main 2026-05-29 02:25:58 +00:00
Owner

Problem

Issue #3 (User Authentication) was re-opened after initial merge of PR #12. Root cause: broken Axios error handling in AuthContext.tsx — err.message produced "Request failed with status code 400" instead of actual validation errors.

Fixes

  1. Error extraction — extractErrorMessage() parses err.response.data, handles DRF error shapes
  2. Token refresh interceptor — Axios 401 interceptor calls /api/auth/token/refresh/, replays queued requests
  3. Backend refresh endpoint — Added TokenRefreshView to accounts/urls.py
  4. Auth state restoration — Restores user profile from localStorage on page reload
  5. ProtectedRoute — Route guard redirects unauthenticated users to /login
  6. Route restructure — Public routes outside ProtectedRoute in App.tsx

Verification

  • tsc --noEmit — 0 errors
  • vite build — builds successfully
  • python manage.py check — 0 issues

Closes #3

## Problem Issue #3 (User Authentication) was re-opened after initial merge of PR #12. Root cause: broken Axios error handling in AuthContext.tsx — err.message produced "Request failed with status code 400" instead of actual validation errors. ## Fixes 1. **Error extraction** — extractErrorMessage() parses err.response.data, handles DRF error shapes 2. **Token refresh interceptor** — Axios 401 interceptor calls /api/auth/token/refresh/, replays queued requests 3. **Backend refresh endpoint** — Added TokenRefreshView to accounts/urls.py 4. **Auth state restoration** — Restores user profile from localStorage on page reload 5. **ProtectedRoute** — Route guard redirects unauthenticated users to /login 6. **Route restructure** — Public routes outside ProtectedRoute in App.tsx ## Verification - tsc --noEmit — 0 errors - vite build — builds successfully - python manage.py check — 0 issues Closes #3
marko added 1 commit 2026-05-29 00:14:30 +00:00
marko added 1 commit 2026-05-29 02:25:07 +00:00
Resolved conflicts in:
  - api/accounts/urls.py: Took main's complete URL set (verify/refresh/logout/me)
  - web/src/App.tsx: Took main's route structure with PublicRoute/ProtectedRoute wrappers
  - web/src/services/authApi.ts: Combined main's robust interceptor with PR's extractErrorMessage + getAccessToken/getRefreshToken helpers
  - web/src/contexts/AuthContext.tsx: Combined main's full auth flow (refreshAccessToken, getProfile, logoutUser) with PR's extractErrorMessage and user_data persistence
crisleo94 merged commit a6c14b52fd into main 2026-05-29 02:25:58 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: HermesFactory/job-tracker#15