question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to tell when authentication is loading, onAuthStateChanged called indeterminate amount of times.

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
bojeil-googlecommented, Feb 25, 2018

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/

4reactions
bojeil-googlecommented, Oct 26, 2017

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:

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User logged in.
  } else {
   // Show UI to login. This can be either triggered on initial sign in or on return from redirect
   // to complete the pending redirect.
    ui.start('#firebaseui-auth-container', uiConfig);
  }
});

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase onAuthStateChanged is being called twice upon login
I'm trying to login using React + Redux. When I click 'Login', it will log me in once, then the onAuthStateChanged is called...
Read more >
How to handle the firebase authentication session to have the ...
This calls signOut() first (causing onAuthStateChanged to report a null) and then reauthenticates the user. Instead, you should use onAuthStateChanged() to see ......
Read more >
.onAuthStateChanged is being called multiple times : r/Firebase
I have the following code: auth.onAuthStateChanged((user) => { if (user) { console.log("user logged in: ", user); } else { console.log("user ...
Read more >
Viewing online file analysis results for 'Protetor_ID.apk'
Has the ability to send SMS; Fingerprint: Has the ability to identify network operator related data. Has the ability to read the device...
Read more >
Add simple authentication to your React app using Firebase
User authentication can is notoriously tricky. Cookies, tokens, sessions, signatures.. Ain't nobody got time for dat!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found