Delete an auth firebase log

-1

I need to delete a Firebase Auth record, I'm using the following code:

        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    user.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {

        }
    });

But you're giving an error:

  

java.lang.NullPointerException: Attempt to invoke virtual method   'com.google.android.gms.tasks.Task   com.google.firebase.auth.FirebaseUser.delete () 'on a null object   reference

Does anyone know what I'm doing wrong or how do I delete a Firebase Auth record?

    
asked by anonymous 13.12.2018 / 17:15

1 answer

0

Most likely that the user is returning null .

The cause of it being returned null may be connected to Authentication. Are you authenticating the user?

Make a validation on your Activity as shown below:

@Override
public void onStart() {
    super.onStart();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();
    updateUI(currentUser);
}

Add task.isSuccessful() to your user.delete () method to validate:

user.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                Log.d(TAG, "User account deleted.");
            }
        }
});

Sources:

Get Started with Firebase Authentication on Android

Manage users on Firebase

    
14.12.2018 / 13:55