简体   繁体   中英

How to remove user authentication and user account in Realtime database at the same time?

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.

在此处输入图片说明

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

在此处输入图片说明

 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.

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM