0

I want to create a function where user can remove their own account. If the user removes their account. All their information will be deleted and user authentication also will be removed. I have created the function but somehow at the Firebase authentication the user email did not get deleted.

enter image description here

The picture above shows the account has been deleted but inside the authentication the account still not gets deleted.

enter image description here

 delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    AlertDialog.Builder dialog = new AlertDialog.Builder(CustProfileActivity.this);
                    dialog.setTitle("Are you sure?");
                    dialog.setMessage("Deleting this account will result in completely removing your " +
                            " account from the system and you won't be able to access the app.");
                    dialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            progBar.setVisibility(View.VISIBLE);
                            FirebaseDatabase.getInstance().getReference().child("Customer").child(firebaseAuth.getCurrentUser().getUid()).removeValue();
                            currentUser.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task) {
                                    if (task.isSuccessful()){
                                        progBar.setVisibility(View.GONE);
                                        Toast.makeText(getApplicationContext(), "Account Deleted", Toast.LENGTH_SHORT).show();
                                        Intent intent= new Intent(getApplicationContext(),LoginActivity.class);
                                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                        startActivity(intent);
                                    } else {
                                        Toast.makeText(getApplicationContext(), task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                        }
                    });
                    dialog.setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                        }
                    });
                    AlertDialog alertDialog = dialog.create();
                    alertDialog.show();
                }
            });


I want to achieve a result where user account will get deleted including their data inside the firebase authentication.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
last gg
  • 87
  • 1
  • 9
  • Do you have any errors? Please log into the console `task.getException().getMessage()` if the task is not successful. What are your security rules? Please add them to your question. – Alex Mamo Jan 20 '20 at 15:05
  • the account got deleted from firebase realtime database but not from the authentication – last gg Jan 20 '20 at 15:06
  • Please answer the question from the first comment. – Alex Mamo Jan 20 '20 at 15:08

2 Answers2

0

Actually I didn't know deep dive firebase. But I think, you can use this method:

Create a cloud function. This function will do, when you delete user on Realtime Database, function is triggering for delete user on Authentication.

You can do you want using the documentation. https://firebase.google.com/docs/database/extend-with-functions

0

Deleting data from Realtime Database will not also delete an account registered with Firebase Authentication. If you want the user to be able to delete their own account, you will have to call FirebaseUser.delete() as shown in the documentation.

See also: How to delete a Firebase user from Android App?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441