The Firebase Auth doc's recommended way to get the current user is:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
// User is signed in
} else {
// No user is signed in
}
So I went ahead and did exactly that at the very beginning of my first activity:
override fun onCreate(savedInstanceState: Bundle?) {
Log.d(TAG, "⟳ onCreate")
super.onCreate(savedInstanceState)
if (FirebaseAuth.getInstance().currentUser == null) {
Log.d(TAG, "User is null. Sending user to log in.")
val intent = Intent(this, FacebookLoginActivity::class.java)
startActivity(intent)
finish()
} else {
Log.d(TAG, "User has been found. Launching MainActivity")
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
}
}
But this is when strange things start happening ????
Steps:
- I killed the app from memory
- Deleted all its data & cache
Uninstall & install again then launch
Actual:
FirebaseAuth.getInstance().currentUserwas NOT null! Okay guessing the Firebase library is trying to do something smart and figure out my previous log in history, but:- The uid it returns is not my user Id. I cannot use this as I already keep data for the user in my DB with an other legit uid previously returned for this user.
- I can NOT find this uid on https://console.firebase.google.com/u/0/project/.../authentication/users How is this possible?
- This uid has been popping up at various times causing me errors, and it is always this same rogue uid.
A couple of things I checked:
FirebaseAuth.getInstance().currentUser.providerDatashows that this uid is associated with my Facebook account, so I must have logged in with it before. (I callFacebookAuthProvider.getCredential(...)in the next activity) But my real legit uid should also be associated with my Facebook account which is the one I am interested in.FirebaseAuth.getInstance().currentUser.isAnonymous returns false, so the problem is probably not related anonymous login
How do I clear this "phantom" rogue user id from the system?
How do I check for this? I don't want to call FacebookAuthProvider.getCredential(...) every time the user opens the app.
(Using 'firebase-auth:12.0.1')