3

I am using Firebase Anonymous Authentication.

In case a user has been deleted from the Firebase console, the client still believes the user exists, as it still holds the token.

Each time I start the app, I would like to verify if the user still exists. I found out I can use the FirebaseUser.reload() function.

The documentation says that in case the user's account has been disabled or deleted, the FirebaseAuthInvalidUserException will be thrown: https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser.html#reload()

However this is an asyncronous function, and I am struggling finding out how to catch this exception. Can anyone show me a code sample on how to catch this exception? I have looked all documentation, but I haven't found a sample about this.

Daniele B
  • 19,801
  • 29
  • 115
  • 173

1 Answers1

3

Try this:

mFirebaseUser.reload().addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
        if (e instanceof FirebaseAuthInvalidUserException) {
            Log.d(TheApp.LOG_TAG, "user doesn't exist anymore");
            createUser();
        }
    }
});
Daniele B
  • 19,801
  • 29
  • 115
  • 173
Bruno Ferreira
  • 1,561
  • 1
  • 10
  • 17