【问题标题】:delete firebase database and authentication in the same time同时删除firebase数据库和身份验证
【发布时间】:2019-07-21 05:37:26
【问题描述】:

首先,我有一个页面供用户将他们的帐户注册到 firebase。他们必须输入他们的姓名、ID、电子邮件和密码。然后电子邮件将在 Firebase 身份验证中注册,名称、ID、电子邮件将保存在 Firebase 数据库中。现在,我尝试同时删除用户数据并删除身份验证。假设我以管理员身份登录,我想删除图像中附加的数据,如何同时删除选定的用户数据库和身份验证?

**PS:数据显示在列表视图中,长按选择要删除的用户。

这是我的代码。

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

【问题讨论】:

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


    【解决方案1】:

    您需要分别调用 Firebase 实时数据库 API 和 Firebase 身份验证 API 以删除相应的部分。没有 API 调用可以同时删除两者。

    最接近的方法是从应用程序代码中删除用户帐户,然后让云函数删除相应的数据库节点。

    我们之前对此有过一些疑问:

    【讨论】:

    • 是否有关于删除 Firebase 身份验证的链接?
    • 你的意思是像deleting a user上的文档。
    • 你提供的文件是用户需要登录系统并删除自己,这不适用于我当前的项目。
    • 在这种情况下,您可以使用Admin SDK to delete a user。但是您不能直接从客户端应用程序中使用它。常见的方法是将您需要的 Admin SDK 功能包装在 API 端点(例如使用 Cloud Functions)中,然后从您的应用程序中调用它。请在此处查看我的答案以获取更多信息:stackoverflow.com/questions/54756694/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    • 2017-12-26
    • 1970-01-01
    • 2021-10-23
    • 2018-08-21
    • 2020-05-10
    • 2019-01-28
    相关资源
    最近更新 更多