问题
I have Android app which uses FirebaseAuth and FirebaseDatabase functionalities. Everything was working fine.
During last week I was working with one user (user 1) as an admin of the app and yesterday I registered another user (user 2) as a normal user(not admin).
Since all my admin functionalities were working fine, I never logged in as the user 1 again. However I had to uninstall my app today and by that time I was logged in as user 2.
When I reinstalled it again, I was automatically logged in as user 1 for some reason. So I logged out and logged in as user 2 again and uninstalled again. The same thing happened again and again.
I checked the user ID I am getting from the FirebaseAuth and its the user 1's user ID which I had logged out previously.
FirebaseAuth auth = FirebaseAuth.getInstance();
if(auth !=null)
{
String uid = auth.getCurrentUser.getUid();
}
Please help me to solve this issue and I have added my logged out code below.
AuthUI.getInstance()
.signOut(ShopHome.this)
.addOnCompleteListener(new OnCompleteListener<Void>() {
public void onComplete(@NonNull Task<Void> task) {
// Code for login Activity
}
});
回答1:
You are using FirebaseUI-Android which uses Smart Lock to automatically log you in, even after after an uninstall of the app. If you do not want to automatically log-in, you can disable automatic sign in with Smart Lock.
回答2:
Make a new emulator with a different device. This is the way I bypassed this issue.
来源:https://stackoverflow.com/questions/37887007/firebaseauth-getinstance-getcurrentuser-returns-previously-logged-out-user