0

First of all, I have a page for user to register their account to firebase. They have to insert their name, ID, email, and password. Then the email will register in the Firebase Authentication and the name, ID, Email will save in the Firebase Database. Now, I try to delete the user data and delete the Authentication in the same time. Suppose I login as Admin and I want to delete the data as attach in the Image, how can i delete the selected user both database and authentication in the same time ?

**PS: The data is show in the List View and LongClick to select user to delete.

enter image description here

Here is my code.

listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(ActivityAdminPage.this);
            alertDialog.setTitle("Are You Sure?");
            alertDialog.setMessage("Delete the User and the User will not longer able to Login to the " +
                    "System anymore.");
            alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    DatabaseReference databaseR = FirebaseDatabase.getInstance().getReference("User");
                    databaseR.removeValue();
                }//end of YES Button Click
            });

            alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //do ntg
                }
            });

            alertDialog.create();
            alertDialog.show();
            return true;
        }//End of Long Click
David Adam
  • 172
  • 1
  • 12

1 Answers1

0

You'll need to make separate calls to the Firebase Realtime Database API, and to the Firebase Authentication API to remove the respective parts. There is no API call that deletes both at once.

The closest to that you can come is deleting the user account from your application code, and then having a Cloud Function delete the corresponding database nodes.

We've had some questions about that before:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • is there any link regarding delete the Firebase Authentication ? – David Adam Feb 27 '19 at 15:49
  • You mean like the documentation on [deleting a user](https://firebase.google.com/docs/auth/android/manage-users#delete_a_user). – Frank van Puffelen Feb 27 '19 at 15:52
  • the doc u gave is user need to login to the system and delete themselves, that wont work for my current project. – David Adam Feb 27 '19 at 15:54
  • In that case you can use the [Admin SDK to delete a user](https://firebase.google.com/docs/auth/admin/manage-users#delete_a_user). But you can't use that directly from the client-side app. The common approach is to wrap the Admin SDK functionality you need in an API endpoint (for example with Cloud Functions) and then call that from your app. See my answer here for more: https://stackoverflow.com/questions/54756694/nativescript-how-to-login-as-an-admin-and-manage-user-account-in-firebase/54756800#54756800 – Frank van Puffelen Feb 27 '19 at 16:31