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 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
// 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();
|
||||
|
||||
Reference in New Issue
Block a user