How to make a user sign out in Firebase?

前端 未结 13 1648
猫巷女王i
猫巷女王i 2020-12-15 04:22

I am making a simple authentication app in Android using Firebase authentication. Till now I am successful in signing the user in, however the issue is that the user remains

13条回答
  •  长情又很酷
    2020-12-15 05:02

    This can be solved by using AuthStateListener

    //Declaration and defination
    private FirebaseAuth firebaseAuth;
    FirebaseAuth.AuthStateListener authStateListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if (firebaseAuth.getCurrentUser() == null){
                //Do anything here which needs to be done after signout is complete
                signOutComplete();
            }
            else {
            }
        }
    };
    
    //Init and attach
    firebaseAuth = FirebaseAuth.getInstance();
    firebaseAuth.addAuthStateListener(authStateListener);
    
    //Call signOut()
    firebaseAuth.signOut();
    

    Snippet : https://codepad.co/snippet/aPeehdoD

提交回复
热议问题