fix: stop AuthContext.getSession clobbering session-derived user (#223) - #231
Open
vedant7007 wants to merge 2 commits into
Open
fix: stop AuthContext.getSession clobbering session-derived user (#223)#231vedant7007 wants to merge 2 commits into
vedant7007 wants to merge 2 commits into
Conversation
…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
|
@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. |
Contributor
Author
|
hey! heads up — the failing this PR doesn't touch |
This was referenced Jul 19, 2026
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
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:
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
Fixes #223