Skip to content

fix: stop AuthContext.getSession clobbering session-derived user (#223) - #231

Open
vedant7007 wants to merge 2 commits into
arzoo0511:mainfrom
vedant7007:fix/authcontext-session-user-223
Open

fix: stop AuthContext.getSession clobbering session-derived user (#223)#231
vedant7007 wants to merge 2 commits into
arzoo0511:mainfrom
vedant7007:fix/authcontext-session-user-223

Conversation

@vedant7007

Copy link
Copy Markdown
Contributor

Summary

The `getSession().then(...)` handler in `AuthContext.tsx` called `setUser` twice back-to-back. React batches both calls (same microtask) so the second wins, unconditionally discarding whatever the first computed. The first call already covered all three cases (session → `toAppUser`, guest-mode → `guestUser`, else → `null`) so the second was pure noise.

Effects:

  • authenticated users saw a logged-out flash on every load until `onAuthStateChange` fired again to restore session
  • `ProtectedRoute`, `GameProvider`, and Community fetch could race against a `null` user on the first render, causing spurious redirects to `/login` and empty states
  • in guest mode, the merge-prompt path was skipped because `login` was never actually called with the session's user

What changed

Deleted the redundant `setUser(isGuestMode() ? guestUser : null)` on line 158. That's it — 1 removed line + a small comment explaining the invariant.

Test plan

  • verified the preceding ternary covers all three states
  • no other file references the discarded value
  • once maintainer approves: manually sign in, close tab, reopen, confirm dashboard renders with the user's profile immediately with no logged-out flash

Fixes #223

…derived user (arzoo0511#223)

The `getSession().then(...)` handler was calling `setUser` twice back to
back. Both calls run in the same microtask so React batches them and
the last one wins. The first call already handled all three states
(session → toAppUser, guest-mode → guestUser, else → null); the second
call unconditionally overwrote it with the guest/null value, meaning
authenticated users saw a logged-out flash on every load until
onAuthStateChange fired to recover.

Any downstream effect that read `user` on the first render (GameProvider,
Community fetch, ProtectedRoute) also raced against a `null` for one
render, causing spurious redirects and empty states.

Delete the redundant call. The preceding ternary already covers all
three branches correctly.

Fixes arzoo0511#223
@vercel

vercel Bot commented Jul 11, 2026

Copy link
Copy Markdown

@vedant7007 is attempting to deploy a commit to the arzoorai0207-5745's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vedant7007

Copy link
Copy Markdown
Contributor Author

hey! heads up — the failing Verify Codebase check is red because of a pre-existing issue on master: src/App.tsx:13 imports ./pages/Auth but no Auth file exists in src/pages/. every PR opened right now fails on the same import resolution error (see [Failed to resolve import "./pages/Auth" from "src/App.tsx"] in the run log).

this PR doesn't touch App.tsx or anything in src/pages/, so nothing here is causing it. happy to open a separate PR restoring the Auth page (or wiring the route to whatever the intended replacement is) if you can point me at what should live there. thanks!

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.

[Bug] AuthContext getSession handler overwrites session-derived user with null on every load

1 participant