【问题标题】:How to remove user authentication and user account in Realtime database at the same time?如何同时删除实时数据库中的用户身份验证和用户帐户?
【发布时间】:2020-01-20 13:18:20
【问题描述】:

我想创建一个功能,用户可以在其中删除自己的帐户。如果用户删除了他们的帐户。他们的所有信息都将被删除,用户身份验证也将被删除。我已经创建了该功能,但不知何故在 Firebase 身份验证中,用户电子邮件没有被删除。

上图显示账号已被删除,但在认证过程中账号仍未被删除。

 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();
                }
            });


我想达到这样一个结果,即用户帐户将被删除,包括他们在 firebase 身份验证中的数据。

【问题讨论】:

  • 你有什么错误吗?如果任务不成功,请登录控制台task.getException().getMessage()。你的安全规则是什么?请将它们添加到您的问题中。
  • 帐户已从 firebase 实时数据库中删除,但未从身份验证中删除
  • 请回答第一条评论中的问题。

标签: java android firebase firebase-realtime-database firebase-authentication


【解决方案1】:

其实我不知道深潜火力基地。但我认为,你可以使用这种方法:

创建云函数。这个功能会做, 当您在实时数据库中删除用户时,会触发删除身份验证用户的功能。

您可以根据需要使用文档。 https://firebase.google.com/docs/database/extend-with-functions

【讨论】:

    【解决方案2】:

    从实时数据库中删除数据不会同时删除通过 Firebase 身份验证注册的帐户。如果您希望用户能够delete their own account,则必须调用FirebaseUser.delete(),如documentation 所示。

    另见:How to delete a Firebase user from Android App?

    【讨论】:

      猜你喜欢
      • 2014-10-01
      • 2021-03-25
      • 2020-12-30
      • 2020-11-12
      • 2020-04-18
      • 2018-07-15
      • 2019-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多