Repository navigation
Cookie-based session model, admin role gate and 401 handling - #2049
Merged
yusuftomilola merged 1 commit intoOct 18, 2026
Merged
yusuftomilola merged 1 commit into
yusuftomilola merged 1 commit into
Conversation
…e-bit) - Adopt the backend's HttpOnly accessToken cookie as the single session store: every fetch sends credentials: "include", the js-cookie mirror and all bearer-header/token threading are removed from the client, and the session store keeps only the in-memory copy of the login token plus the user (Closes DistinctCodes#1975) - Add GET /auth/me (backend) and useSessionBootstrap so a reload restores who is signed in without reading cookies from JavaScript, fixing the hydration-mismatch class of bugs at the source - Gate /admin routes by role: middleware decodes the verified admin claim and redirects members to a new /admin/forbidden page; RequireAdmin is rewritten as a session-driven client backstop with a not-authorised state (Closes DistinctCodes#1973) - React to rejected sessions centrally: expireSession() clears the store, toasts once and redirects to /login?returnTo=... with loop protection, wired into every *-api helper (Closes DistinctCodes#1977) - Add logout() (POST /auth/logout with credentials), a shared useSignOut hook and a UserMenu on wallet, payments, usage, credits and admin headers so sign-out reaches the backend everywhere (Closes DistinctCodes#1974) Notes for reviewers: - Backend change is limited to the new GET /auth/me endpoint reading the guarded request user; login/register/logout are untouched. - The api modules' tests keep the same behavior coverage: the "Bearer" header assertions were dropped (no client-side bearer) and the wallet credentials expectation moved from same-origin to include. - Keep an eye on merge order with DistinctCodes#1976 (shared lib/http.ts by devrabiuhussain): both PRs touch the five *-api modules and their callers. DistinctCodes#1976 keeps an optional accessToken param for compatibility; this PR removes the parameter and headers entirely, so resolve in favor of this one's cookie session semantics. - The query-client side of the 401 reaction (skip retries for 401/403) lands with the providers consolidation in DistinctCodes#1980 to avoid both PRs editing the same provider files.
|
@ykargeee-bit is attempting to deploy a commit to the naijabuz's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@ykargeee-bit Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Closed
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the auth session hardening assigned to ykargeee-bit:
credentials: "include"with the backend's HttpOnlyaccessTokencookie; the js-cookie mirror and all bearer/token threading are removed from the client. The session store keeps only an in-memory copy of the login token plus the user. NewGET /auth/meendpoint restores session/role after reload./admin/forbiddenpage;RequireAdminrewritten as a session-driven client backstop with a not-authorised state.logout()(POST /auth/logout with credentials), shareduseSignOuthook, andUserMenuon wallet, payments, usage, credits and admin headers.expireSession()clears the store, toasts once, and redirects to/login?returnTo=...with loop protection, wired into every *-api helper. Parallel 401s are coalesced via a module flag.Backend changes
Limited to the new
GET /auth/meendpoint (reads the guarded request user). Login/register/logout are untouched.Test updates
auth-form.test.tsx— setSession, role "user"payments-api.test.ts/credits-api.test.ts/wallet-api.test.ts— removed Bearer/Authorization assertions (no client-side bearer); wallet credentials expectation moved toincludepayment-return-page.test.tsx— user/status mock + bootstrap mockrequire-admin.test.tsx— rewritten for the role-based gatesession-expiry.test.ts,auth-api.test.ts,api-401.test.ts,middleware.test.ts,app/payments/__tests__/page.test.tsxMerge coordination
accessTokenparam for compatibility; this PR removes the parameter and headers entirely. Resolve in favor of this PR's cookie session semantics.Closes #1975
Closes #1977
Closes #1974
Closes #1973