Fix: No error handling around onAuthStateChanged listener - #351
Closed
khushboo-khatoon wants to merge 1 commit into
Closed
Fix: No error handling around onAuthStateChanged listener#351khushboo-khatoon wants to merge 1 commit into
khushboo-khatoon wants to merge 1 commit into
Conversation
|
@khushboo-khatoon is attempting to deploy a commit to the Nitya Gosain's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
hey @Nitya-003 , PR is now ready to review and merge . |
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.
Fixes #343
Description
The
onAuthStateChangedlistener in theuseAuthhook only provided a success callback (onNext). It didn't use the thirdonErrorcallback that Firebase supports, so if the listener itself hit an internal error (e.g. a token refresh failure), there was no way to handle it.Since
setLoading(false)was only called inside the success callback, an error in the listener could leaveloadingstuck astrueforever — causing the app to appear stuck (e.g. an infinite loading spinner) with no indication of what went wrong.Changes
onErrorcallback toonAuthStateChanged.console.error, defaultsusertonull, and setsloadingtofalseso the app never gets stuck in an infinite loading state.File
frontend/hooks/useAuth.tsBefore
After
How to Test
useAuthhook.onAuthStateChangedlistener (e.g. temporarily mock the listener to invoke its error callback instead of the success callback).loadingbecomesfalseanduserbecomesnull, instead of the app hanging indefinitely in a loading state.Impact
Prevents the app from getting stuck in an infinite loading state if the Firebase Auth listener encounters an internal error — a rare but possible production issue that would otherwise be silent and hard to debug.
Checklist