Firebase Auth: How can I detect that firebase trying to auto signIn current user?

不羁岁月 提交于 2021-02-10 08:46:19

问题


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:

  1. User sees login form (not touching anything)
  2. 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
  3. User thinks that he need to fill login form
  4. After 1 - 1.5 seconds, triggered onAuthStateChanged and login form disappears
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!