Firebause getCurrentUser().getEmail returns null

I developed an android application and in one of my activities, I give the user possibility to delete his account.

The deletion process does many things and at the end of the process, I delete the user itself.

I do it by using this:

new CountDownTimer( 7000, 500 ) {
    @Override
    public void onTick(long millisUntilFinished) {
    }

    @Override
    public void onFinish() {

        FirebaseUser user = auth.getCurrentUser();
        AuthCredential credential = EmailAuthProvider.getCredential( user.getEmail(), password );
        user.reauthenticate( credential ).addOnCompleteListener( task -> user.delete() );

        auth.signOut();

        AuthUI.getInstance()
                .signOut( context )
                .addOnCompleteListener( task -> {
                    Intent intent = new Intent( context, MainActivity.class );
                    intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP |
                            Intent.FLAG_ACTIVITY_CLEAR_TASK |
                            Intent.FLAG_ACTIVITY_NEW_TASK );
                    context.startActivity( intent );
                } );

        MainActivity.isDeleted = true;
    }

}.start();

However, I just got a log from one of the users where it says the app crashed due to:

Attempt to read from field 'c.d.d.g...' on a null object reference

com.google.firebase.auth.internal.zzx.getEmail (zzx.java:4) 

What I understand is that user.getEmail was null.

In all of the other activities, if I see that there is no user, I just direct to the Main activity. But here, it happened in the end of the deletion process and the whole data is deleted except to the user it self and it is problematic to direct them to the main activity, sign in again and go back to delete process.

How can I make sure that there will be a valid user when I get to this stage?

I also thought it might be due to the 7000 that I set which is used to make sure that the whole database is deleted before I end with user.delete.

Thank you



Read more here: https://stackoverflow.com/questions/66993505/firebause-getcurrentuser-getemail-returns-null

Content Attribution

This content was originally published by Ben at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: