Delete a log from firebase auth

Asked

Viewed 718 times

-1

I need to delete a record from Firebase Auth, I am using the following code:

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

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

        }
    });

But it’s making a mistake:

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 I delete a record of Firebase Auth?

  • useris certainly null. You do not have a user logged in with this instance of Firebaseuth. If you want to delete a specific user and not the connected user himself (like an Administer/superuser) use Firebase Console.

  • I want to delete the user q is current, for example... after he leaves a login validation page, without having validated using a code that is sent by sms (all ready so far), his user is deleted from the bank, because he has not finished his registration.

  • Got it. But your Firebaseuth has no users, maybe it hasn’t even been created in the first place.

1 answer

0


Very likely the user is returning null.

The cause of him returning null may be connected to Authentication. You are authenticating the user?

Perform a validation on your Activity as an example 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 the task.isSuccessful() in 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 in Firebase

  • This "updateUI" method doesn’t exist! I’m using Firebase Auth 'com.google.firebase:firebase-auth:11.8.0'

  • Strange, it’s supposed to exist, see if there’s any import.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.