Description
While reviewing the authentication flow, I noticed that the Firestore onSnapshot listener used in AuthContext.tsx does not include an error callback.
Currently, the loading state is only cleared when the snapshot successfully returns data. If Firestore encounters an error during the initial read (for example, due to permission issues, connectivity problems, or missing documents), the success callback never executes and the loading state is never updated.
As a result, users can become stuck on a loading screen indefinitely.
Why This Matters
Authentication is one of the first systems users interact with. If the initial Firestore sync fails and the loading state is never resolved, the application appears frozen even though the underlying issue may be recoverable.
Adding proper error handling would make the authentication flow more resilient and provide a better user experience during unexpected Firestore failures.
Evidence
Location:
src/context/AuthContext.tsx
Around lines 308–342, onSnapshot() is registered without an error callback.
Current pattern:
onSnapshot(
doc(db, collectionName, docId),
(docSnapshot) => {
// success logic
setIsLoading(false);
}
);
If the listener fails, setIsLoading(false) is never reached.
Impact
- Users may become stuck on a loading screen indefinitely.
- Firestore failures are not handled gracefully.
- Makes debugging authentication issues more difficult.
- Creates a poor first-time user experience during network or permission failures.
Suggested Fix
Add an error callback to the Firestore listener and ensure the loading state is always resolved.
Example:
unsubscribeSnapshot.current = onSnapshot(
doc(db, collectionName, docId),
(docSnapshot) => {
// existing success logic
setIsLoading(false);
},
(error) => {
console.error("Firestore user sync error:", error);
setIsLoading(false);
}
);
Optionally, a user-facing error state could be shown in the future, but resolving the loading state should be the minimum requirement.
Acceptance Criteria
Description
While reviewing the authentication flow, I noticed that the Firestore
onSnapshotlistener used inAuthContext.tsxdoes not include an error callback.Currently, the loading state is only cleared when the snapshot successfully returns data. If Firestore encounters an error during the initial read (for example, due to permission issues, connectivity problems, or missing documents), the success callback never executes and the loading state is never updated.
As a result, users can become stuck on a loading screen indefinitely.
Why This Matters
Authentication is one of the first systems users interact with. If the initial Firestore sync fails and the loading state is never resolved, the application appears frozen even though the underlying issue may be recoverable.
Adding proper error handling would make the authentication flow more resilient and provide a better user experience during unexpected Firestore failures.
Evidence
Location:
Around lines 308–342,
onSnapshot()is registered without an error callback.Current pattern:
If the listener fails,
setIsLoading(false)is never reached.Impact
Suggested Fix
Add an error callback to the Firestore listener and ensure the loading state is always resolved.
Example:
Optionally, a user-facing error state could be shown in the future, but resolving the loading state should be the minimum requirement.
Acceptance Criteria
onSnapshotlistener.isLoadingis cleared when snapshot initialization fails.