Repository navigation
fix: proper auth race condition fix (replaces #75) - #82
Merged
Merged
Conversation
…ing auth ready PR #75 fixed the green screen bug on direct game links by using onAuthStateChanged, but introduced a new race condition: it set isLoading=false before the token refresh completed, so downstream code (like useCreateGame) could call getIdToken() and get stale tokens. This fix keeps onAuthStateChanged for fast auth pickup on returning users, but crucially awaits the token refresh BEFORE setting isLoading=false. This ensures: - Splash screen stays visible until auth is FULLY ready (userId + token) - No green screen on direct game links - No token race conditions for downstream API calls Replaces the approach from PR #75 (commit e3a06b2).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The GameScreen was rendering an empty green ScreenContainer when auth or game data wasn't ready yet. On mobile Safari, the splash screen hides before the game screen has its data, leaving users staring at a blank green screen. Now properly distinguishes between: - Loading (auth pending or game data loading) → shows spinner - Game not found (null) → empty screen (useGame redirects home) - Ready → renders the game This is the actual fix for the mobile Safari green screen issue.
Root cause: useGame() subscribed to Firestore immediately on mount, before Firebase Auth completed. On mobile Safari (where auth is slower than desktop Chrome), this caused either permission errors or empty snapshots, which triggered a premature redirect to '/' — resulting in a blank green screen. Fix: - useGame: skip Firestore subscription until auth is ready (isLoading=false && userId set) - GameScreen: show spinner instead of empty green screen when game is null (redirecting)
This branch was successfully deployed
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.
What PR #75 was trying to fix
PR #75 (
e3a06b2) fixed a blank green screen that appeared when opening a game link directly (e.g./games/1234). The root cause was that the splash screen hid before auth completed.Why PR #75's approach introduced new race conditions
PR #75 changed AuthProvider to use
onAuthStateChangedand setisLoading=falseimmediately when the user was detected, refreshing the token in the background (fire-and-forget). This meant:userIdwas set andisLoadingwas false BEFORE the token refresh completeduseCreateGamechecksisLoadinganduserIdbefore callinggetIdToken()What this fix does differently
This fix keeps
onAuthStateChanged(which is faster thansignInAnonymouslyfor returning users since Firebase caches auth state) but awaits the token refresh before settingisLoading=false:This ensures:
How it was tested
/games/{PIN}— game loaded correctly, no green screen