If I delete a user directly from my Firebase Console, this user still have a valid data on my Android Device.
Of course if I then access firebase resources (e.g. Realtime Database) that doesn't work as expected.
But this cause a misalignment in the client because if I have valid user data I show a specific UI for authenticated users, instead if I have no user authenticated I show another UI.
How could I manage this situation?
EDIT: what I've found, but I don't now if that is okay or is a workaround is to call the reload() on my FirebaseUser.
From the documentation this should throw and Exception but that doesn't happen. What happens is that my user reference become null:
private void initializeUI(FirebaseUser user) {
user.reload();
if (null != user) {
mUser = user;
} else {
// User must have been disabled or deleted from console
}
I call initializeUI here:
@Override
public void onAuthStateChanged(@NonNull final FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (null != user) {
initializeSignInUI(user);
} else {
initializeSignOutUI();
}
}
As a more info:
If I open my App the user is still alive on client side. The trigger for authentication user is fired and here, with my code above I can manage the situation. But I don't know if this is actually a workaround or the right practice.
EDIT 2 Just to reformulate my question:
This method is working well:
public boolean validUser(FirebaseUser user) {
boolean validUser = false;
if (null != user) {
try {
user.reload();
if (null != user) {
validUser = true;
}
} catch (Exception e) {
//} catch (FirebaseAuthInvalidUserException e) {
validUser = false;
}
}
return validUser;
}
Could I consider that a valid solution or there'a another best practice? This solution works only with FirebaseAuth without the need of interact with FirebaseDatabase. I can call this method every time have to check the user authentication.