[英]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?美好的一天,你们知道如何使用 firebase 身份验证帐户同时从实时数据库中删除数据吗? 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?
此代码已经在工作,已经仅从实时数据库中删除数据,有什么方法可以将其与 Firebase 身份验证帐户一起删除? Basicall my UUID from Firebase Auth and my Child from Realtime DB is the same as well.
基本上我的来自 Firebase Auth 的 UUID 和来自 Realtime DB 的孩子也是一样的。
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供参考,这里是 Firebase 身份验证中的帐户图像
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.
实时数据库和 Firebase Auth 是具有不同 API 的不同产品,您必须单独使用它们的 API 才能完成这项工作。
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 .如果您尝试使用当前登录用户以外的其他用户的数据和帐户,则需要使用Firebase Admin SDK在后端完成所有这些工作。 And again, you will need to deal with each product's APIs separately.
同样,您需要分别处理每个产品的 API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.