简体   繁体   中英

How to delete user from Realtime Database and Firebase Authentication? Android Java

Good day, do you guys know how to delete a data from realtime database at the same time with firebase auth account? This code is already working already deleting the data from the Realtime Database only, is there any way on how to delete it alongside with Firebase Authentication account? Basicall my UUID from Firebase Auth and my Child from Realtime DB is the same as well.

holder.btndel_stud.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Users");
                final DatabaseReference firebaseUser = FirebaseDatabase.getInstance().getReference(FirebaseAuth.getInstance().getUid());
                final String uniqueKey = addingStudentsArrayList.get(position).getUniqueid();
                final String studentName = addingStudentsArrayList.get(position).getFullName();
                databaseReference.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot snapshot) {
                        databaseReference.child(uniqueKey).removeValue().addOnSuccessListener(new OnSuccessListener<Void>() {
                            @Override
                            public void onSuccess(Void aVoid) {
                                Toast.makeText(context, "Deleted User From Database...", Toast.LENGTH_SHORT).show();
                                firebaseUser.removeValue();
                            }
                        });
                    }
                    @Override
                    public void onCancelled(@NonNull DatabaseError error) {

                    }
                });

            }
        });

for reference here's the image of the account in Firebase Authentication在此处输入图像描述

and here's the image of the user's data stored in realtime database. 在此处输入图像描述

It's not possible to do both operations at the exact same moment in time. Realtime Datbase and Firebase Auth are different products with different APIs, and you will have to use their APIs separately to get this job done.

If you want the user to be able to delete their data along with their account, you should write code to first delete the data from the database, then delete the account.

If you're trying to the data and the account for another user other than the one who is currently signed in, you will need to do all this work on a backend using the Firebase Admin SDK . And again, you will need to deal with each product's APIs separately.

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