Unable to tell when authentication is loading, onAuthStateChanged called indeterminate amount of times.
See original GitHub issueI’m having quite a bit of trouble identifying whether firebase authentication is in the process of authenticating my users or not.
Is there a way to tell if there’s a current user authentication check loading/in-process ? If not please accept this as a feature request.
My justification is this:
Since sometimes (mostly on first login), after my app has loaded and firebase auth initialised, there’s several hundred ms delay until the user is returned, I’m trying to show a loading indicator on a user avatar until it’s known whether there is a logged in user or not.
I have tried to use onAuthStateChanged
to toggle loading status, but it seems to be called an indeterminate number of times. I have looked at the docs for android here docs/reference/android/com/google/firebase/auth/FirebaseAuth.AuthStateListener but it doesn’t seem to fully tally with what I’m seeing here.
When I refresh my app, onAuthStateChanged
is called once and the user object from is present or null
, (seemingly without any network requests to google?).
When via redirect, my app is loaded right after logging in, onAuthStateChanged
is called twice: once with null
, and subsequently once more with the user object.
I’d like to be able to tell, even though onAuthStateChanged
has returned a null
user, that the auth is still in progress and I should expect it to be called again on completion.
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:5 (3 by maintainers)
Top GitHub Comments
Your question is not related to firebaseui-web or this thread. Please post your question on stackoverflow. If you are experiencing some bug, then you should post to firebase-js-sdk: https://github.com/firebase/firebase-js-sdk/
onAuthStateChanged
will be called with null and then with the logged in user (when using redirect flow). This is on purpose so you know when to render FirebaseUI. This is unlikely to change. Typically:You have the ability to render FirebaseUI at any time, so you know when the user is about to login.
onAuthStateChanged
will always trigger when the user is logged in.I don’t understand what you exactly want to do. Can you provide snippets with what you are trying to do and how you are trying to sign in the user?