Skip to content

fix: align frontend auth with httpOnly cookie strategy#159

Merged
GitAddRemote merged 2 commits into
mainfrom
fix/ISSUE-158-frontend-cookie-auth
May 16, 2026
Merged

fix: align frontend auth with httpOnly cookie strategy#159
GitAddRemote merged 2 commits into
mainfrom
fix/ISSUE-158-frontend-cookie-auth

Conversation

@GitAddRemote
Copy link
Copy Markdown
Owner

Closes #158

Summary

  • The backend switched to httpOnly cookie auth in bc64610 but the frontend was never updated — data.access_token was undefined at login, so every request sent Authorization: Bearer undefined and got a 401
  • Removes all localStorage token reads/writes across 5 pages and 5 service files
  • Adds credentials: 'include' (fetch) and withCredentials: true (axios) everywhere so cookies are sent automatically on cross-origin requests
  • Replaces ProtectedRoute localStorage check with a real GET /auth/me call — httpOnly cookies are intentionally unreadable from JS
  • Logout now calls POST /auth/logout to revoke the refresh token and blacklist the JTI in Redis (previously just cleared localStorage with no server-side effect)

Test plan

  • Login with demo / password123 — should land on dashboard without 401s in the network tab
  • Hard refresh on a protected route — should stay logged in (cookie persists)
  • Logout — should redirect to /login and a subsequent visit to /dashboard should redirect back to /login
  • Open DevTools → Application → Local Storage — no access_token or refresh_token keys should exist
  • Open DevTools → Application → Cookies — access_token and refresh_token should be present with HttpOnly flag set

The backend switched to httpOnly cookie auth in bc64610 but the frontend
was never updated — login stored data.access_token (undefined) in
localStorage, causing every request to send Authorization: Bearer
undefined and get a 401.

- Remove all localStorage token reads/writes from Login, Register,
  Dashboard, Profile, and Inventory pages
- Add credentials: 'include' to all fetch calls
- Add withCredentials: true to all axios calls in service files
- Replace ProtectedRoute localStorage check with GET /auth/me so
  auth state is verified via cookie (httpOnly cookies are unreadable
  from JS)
- Call POST /auth/logout on logout to revoke the refresh token and
  blacklist the JTI in Redis
Copilot AI review requested due to automatic review settings May 14, 2026 23:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns the frontend with the backend's already-deployed httpOnly cookie auth scheme. Previously the frontend was reading data.access_token from a login response that no longer carries it, then sending Authorization: Bearer undefined on every call — breaking all authenticated flows.

Changes:

  • Removes all localStorage token reads/writes from auth/login/register/profile/dashboard/inventory pages and from five service files; the shared axios instance and every per-call axios/fetch invocation now sends withCredentials: true / credentials: 'include' so cookies travel with cross-origin requests.
  • Replaces ProtectedRoute's localStorage check with a real GET /auth/me call (httpOnly cookies aren't readable from JS).
  • Adds a POST /auth/logout call on logout in Profile, Dashboard, and Inventory so the backend can revoke the refresh token and blacklist the JTI.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
frontend/src/services/uex.service.ts Drops bearer header helper; switches both UEX GETs to withCredentials.
frontend/src/services/permissions.service.ts Drops bearer header helper; uses withCredentials on the user-permissions GET.
frontend/src/services/location.service.ts Drops bearer header; locations + storable-locations now send credentials, preserving If-None-Match.
frontend/src/services/inventory.service.ts Drops bearer header helper across all inventory and org-inventory CRUD calls in favor of withCredentials.
frontend/src/services/api.service.ts Marks the shared axios instance with withCredentials; getProfile no longer takes a token.
frontend/src/pages/Register.tsx Adds credentials: 'include' to register/auto-login fetches and stops storing tokens locally.
frontend/src/pages/Profile.tsx Profile read/update and password-change fetches use cookies; logout calls POST /auth/logout.
frontend/src/pages/Login.tsx Adds credentials: 'include'; no longer parses/stores tokens from the login response.
frontend/src/pages/Inventory.tsx Profile fetch uses cookies; logout now hits the server logout endpoint.
frontend/src/pages/Dashboard.tsx Profile fetch uses cookies; logout now hits the server logout endpoint.
frontend/src/components/ProtectedRoute.tsx Replaces synchronous localStorage check with an async GET /auth/me round-trip and authed state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/pages/Dashboard.tsx Outdated
Comment thread frontend/src/pages/Profile.tsx Outdated
Comment thread frontend/src/pages/Inventory.tsx Outdated
Comment thread frontend/src/components/ProtectedRoute.tsx
Comment thread frontend/src/pages/Login.tsx
- Wrap all three handleLogout fetch calls in try/finally so navigate('/login')
  always runs regardless of network errors or 401 from RefreshTokenAuthGuard
- ProtectedRoute: show CircularProgress spinner while auth check is in flight
  instead of rendering null; only redirect to /login on explicit 401 — network
  errors and 5xx leave the spinner up to avoid booting users on transient failures
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

@GitAddRemote GitAddRemote merged commit cf962cb into main May 16, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: align frontend auth with httpOnly cookie strategy

2 participants