如何通过代码禁用Firebase项目的用户帐户? [英] How can I disable user accounts for a firebase project from code?

查看:74
本文介绍了如何通过代码禁用Firebase项目的用户帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从控制台(firebase网页)成功禁用项目的用户帐户,但是应用程序中的用户如何在需要时通过代码禁用您自己的用户帐户.另外,我在firebase的新文档中找不到帮助.

I can successfully disable user accounts for a project from console (firebase web page) but how can a user from an applicative disable your own user account by code when he wants to do. Also, I don't find help in the new documentation of firebase.

推荐答案

回答这个问题有点老了.但是,仅对于寻找相同答案的人来说,我的答案就会带来想法.

This is a bit old to answer the question. But just for someone who looks for the same answer would get an idea from my answer.

使用管理SDK

Firebase管理员(node.js)(不适用于Mobile平台)可以使用

Firebase admin (node.js)- which is not available for Mobile platform - has the ability to do the disabling/deleting the user by using the Admin SDK. To disable a user, set the disable attribute to TRUE.

注意:如果您的应用程序是 基于浏览器的应用程序.

NOTE: Using the Admin SDK is not possible if your application is browser based application.

使用实时数据库规则

另一个选项是通过在实时数据库中设置用户"表来限制用户对数据库的访问(读/写).您可以在该表中添加标志字段(活动),例如:

The other option is to restrict the user access (read/write) to database by setting Users table in realtime database. You can add a flag field (active) in that table for example:

{
  "users" : {
    "3sFGw6zlr8VylNuvmCWd9xG1CQ43" : {
      "active" : true,
      "address" : "#123, City",
      "createdBy" : "2016-12-20",
      "mobile" : "xxxxxxx"
    },
    "posts" : {
    }
}

在上面的示例中-"3sFGw6zlr8VylNuvmCWd9xG1CQ43"是Firebase身份验证生成的uid.这是将此自定义 users 表与firebase用户配置文件连接的关键.通过正常的数据库写入操作,活动字段可以轻松地设置 true false .

In the above example - "3sFGw6zlr8VylNuvmCWd9xG1CQ43" is the uid generated by firebase authentication. This is the key to join this custom users table with firebase user profile. The active field can easily set true or false with normal database write operation.

此标志字段将用于检查此帐户是否有权访问数据库记录.参见以下示例:

And this flag field will be used to check if this account has access to database records. See below for an example:

{
  "rules": {
    ".read": "auth !== null && root.child('users/' + auth.uid).child('active').val()==true",
    ".write": "auth !== null && root.child('users/' + auth.uid).child('active').val()==true",
  }
} 

此规则将检查用户是否已登录并且标志字段活动为true.否则,用户将无法读取或写入数据库.在用户登录页面上,您还可以检查此标志字段以查看已登录的用户,如果活动字段为false,则注销该用户,以使该用户无法登录系统.

This rule will check if user is logged in and has flag field active true. Otherwise, user will not be able to read or write to database. On the user login page, you can also check this flag field for logged in user and logout the user if active field is false, so that user will not be able to log in to system.

您可以使用其中提供的Cloud Functions(Admin SDK).有时请尝试在此处上阅读有关Cloud Functions的内容. Firebase Cloud Functions是用于实时数据库的非常有用的工具.

You can use Cloud Functions (Admin SDK) is available in there. Try to spare sometimes to read about Cloud Functions here. Firebase Cloud Functions is quite a useful tools for Realtime Database.

这篇关于如何通过代码禁用Firebase项目的用户帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆