Mastering Firebase for Android Development
上QQ阅读APP看书,第一时间看更新

Deleting a user

Most applications allow freedom to delete an account from the application, and we can achieve that by using the delete method of the FirebaseUser object:

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

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

Users will not be able to delete their account if they have not signed in recently; a user can also reauthenticate the credentials to delete the account using the reauthenticate method:

AuthCredential credential = EmailAuthProvider
.getCredential("Vinisha@Ashok.com", "Secret");

user
.reauthenticate(credential)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Log.d(TAG, "User re-authenticated.");
}
});