From 33d831af54efc100b9ffe4e0b820263b4de3d711 Mon Sep 17 00:00:00 2001 From: robert Date: Sat, 16 May 2026 10:53:03 -0400 Subject: [PATCH] Fix race condition causing permissions error on /display page onAuthStateChanged fires with null before signInAnonymously completes, causing DisplayView to query Firestore unauthenticated. Now only marks auth ready when an actual user is present; auth failures are handled in the catch block to avoid hanging the UI. Co-Authored-By: Claude Sonnet 4.6 --- src/App.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 9824feb..5f09dda 100644 --- a/src/App.js +++ b/src/App.js @@ -2658,13 +2658,21 @@ function App() { } catch (err) { console.error("Authentication error:", err); setError("Failed to authenticate. Please try again later."); + // Auth failed and onAuthStateChanged won't fire with a user, so unblock the UI here + setIsAuthReady(true); + setIsLoading(false); } }; const unsubscribe = onAuthStateChanged(auth, (user) => { setUserId(user ? user.uid : null); - setIsAuthReady(true); - setIsLoading(false); + // Only mark auth ready once we have an actual authenticated user. + // onAuthStateChanged fires with null before signInAnonymously completes, + // which would cause Firestore queries to run unauthenticated. + if (user) { + setIsAuthReady(true); + setIsLoading(false); + } }); initAuth();