问题
I'm using firebase.auth().onAuthStateChanged(...) in browser to detect that user is signed in and on every page load firebase trying to signIn current user (probably based on stored token in IndexDB). I need to detect when firebase trying automatically login current, so I can show loader instead of login form.
Issue:
- User sees login form (not touching anything)
- firebase automatically signin this user based on last token stored in IndexDB (it takes near 1 - 1.5 seconds) on this step I want to know about this and show loader to user
- User thinks that he need to fill login form
- After 1 - 1.5 seconds, triggered
onAuthStateChangedand login form disappears - User little bit confused why he saw login form for those 1 - 1.5 seconds without any loader or notification that app trying to sigin him automatically
回答1:
I'm using the following code in my app to know whether user is already signed in or not. I don't know how to do it on browser but I hope you will get little idea by this.
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user!=null){
startActivity(new Intent(MainActivity.this, MainMenu.class));
this.finish();
}
来源:https://stackoverflow.com/questions/59420760/firebase-auth-how-can-i-detect-that-firebase-trying-to-auto-signin-current-user