Reputation: 667
I need to delete at request an user from Firebase but want to be sure that the user delete own account. So I want that user to input his username and password.
I have next code:
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
AuthCredential credential = EmailAuthProvider
.getCredential(txtEmail.getText().toString().trim(),
txtPassword.getText().toString().trim());
assert user != null;
user.reauthenticate(credential)
.addOnCompleteListener(task -> user.delete()
.addOnCompleteListener(task1 -> {
progressDialog.dismiss();
if (task1.isSuccessful()) {
//Log.d(TAG, "User account deleted.");
Toast.makeText(getActivity(), getResources().getString(R.string.delete_ok), Toast.LENGTH_SHORT).show();
final Handler handler = new Handler();
handler.postDelayed(() -> {
//here I try to close my app from a fragment but no success
Activity act = getActivity();
if (act instanceof ActivityHome) {
((ActivityHome) act).onClose();
}
}, 2000);
} else {
Toast.makeText(getActivity(),getResources().getString(R.string.delete_cancel) , Toast.LENGTH_SHORT).show();
}
}));
User is deleted but values for txtEmail and txtPassword are ignored. Can delete the user for any values. User is deleted including for null values.
Any suggestions?
Upvotes: 1
Views: 798
Reputation: 600116
A Firebase Authentication user can only delete their own account. There is no way for them to delete another user's account.
Even deleting your own account, requires that you have recently authenticated. That means that you must either have recently signed in, or call reauthenticate()
.
When you call reauthenticate
Firebase tries to authenticate the current user with the credentials you provide. If the credentials don't match the current user, the operation will fail.
Upvotes: 2