I am developing an android app using firebase for user management and authentication. I was wondering when the auth state listener gets called and how it works, as in my app I have a bug related to this.
Here is an example of one in my android app:
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// Sign in logic here.
}
}
};
How does the AuthStateListener
work and when does it get called?
Firebase Authentication provides backend services, easy-to-use SDKs, and ready-made UI libraries to authenticate users to your app. It supports authentication using passwords, phone numbers, popular federated identity providers like Google, Facebook and Twitter, and more.
As said by @user663031, the answer "no" is correct.
console. log(firebase. auth(). currentUser) // This returns null console.
As the Firebase API says:
AuthStateListener
is called when there is a change in the authentication state.
OnAuthStateChanged
gets invoked in the UI thread on changes in the authentication state:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With