[Frontend] Shared API client with session-expiry handling, abort, and request dedup #103
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The
request()fetch wrapper is copy-pasted across four API modules —src/api/campaigns.js:19,src/api/sessions.js:16,src/api/users.js:8,src/api/planning.js:1— and inlined again insrc/api/auth.js. There is no global 401 handling: auth is checked once at mount (src/hooks/useAuth.jsx:14) and never again. NoAbortControllerexists anywhere in the frontend. The dashboard fires one uncachedfetchNextSessionper campaign card (src/pages/Dashboard.jsx:44, oneSessionCountdownper card at:86).Current behavior
AuthGuardkeeps rendering the app — the user is stuck on a dead page instead of being sent to login.Fix / Spec
src/api/client.jsused by all API modules:/login— via a subscribable event or a callback registered byuseAuth(avoid circular imports).AbortSignaloption and pass it tofetch; pages/components abort in-flight requests in effect cleanup.Mapkeyed by method+URL, GETs only). Do NOT add React Query in this issue.{detail}error-surface contract (errors expose the backend'sdetailmessage).campaigns.js,sessions.js,users.js,planning.js, andauth.jsonto the shared client; delete the copy-pasted wrappers.Acceptance criteria
src/api/*modules import the shared client;grep "async function request"insrc/api/returns nothing.detailstring.References
src/api/campaigns.js:19,src/api/sessions.js:16,src/api/users.js:8,src/api/planning.js:1,src/api/auth.jssrc/hooks/useAuth.jsx:14src/pages/Dashboard.jsx:44,:86Filed from the July 2026 full-project review.