Firebase简单登录 - 防止新用户 [英] Firebase Simple Login - Prevent New Users

查看:110
本文介绍了Firebase简单登录 - 防止新用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Firebase的简单登录电子邮件/密码身份验证功能。



我只想通过Forge 管理用户。我不希望用户通过客户端应用程序创建。



然而,我仍然希望让他们登录/注销。



这是否可能?

解决方案

您无法阻止用户在客户端上使用简单登录。您可以使用两种方法:

简单登录帐户实际上只是令牌



简单登录只是创建Firebase令牌的便捷包装。对于可存储的帐户数量没有限制,它们对您的Firebase使用率没有任何影响。考虑到这一点,确实没有理由限制帐户的创建。



相反,只需要使用安全规则来控制对数据的访问。当管理员创建一个帐户时,让他们也添加一个配置文件到数据中。如果只有Forge中的管理员可以创建配置文件,那么有人可以创建一个帐户,但这将是多余的和毫无意义的,因为它所做的只是给他们一个惰性的标记。



执行数据访问的安全规则:

 。write:root.child('valid_account / '+ auth.uid).exists()

允许用户编辑个人资料的安全规则但是只有Forge(admin:true)才能创建它们:

 profiles:{
$ uid: {
.write:data.exists()&& auth.uid === $ uid& newData.exists()
}
}

创建您自己的令牌允许完全控制

如果你是非常强大的OCD,不喜欢这种方法,那么你可以删除简单的登录。如前所述,它只是代表您创建令牌。因此,只需创建自己的



通过这种方式,您可以完全控制帐户创建和令牌生成。


I am using the Simple Login Email / Password Authentication functionality of Firebase.

I would like to manage users through Forge only. I don't want users to be created via the client app.

However I would still like to let them login/logout though.

Is this possible?

解决方案

You can't prevent users from being created on the client using simple login. There are two options you can utilize instead:

Simple Login "accounts" are really just tokens

Simple Login is just a convenience wrapper that creates Firebase tokens. There is no limit on how many accounts can be stored and they have no affect on your Firebase usage. With this in mind, there's really no reason you need to restrict creation of accounts.

Instead, just utilize security rules to control access to data. When an admin creates an account, have them also add a profile into the data. If only an admin in Forge is allowed to create the profile, then someone could create an account, but it would be superfluous and pointless, since all it does is give them an inert token.

A security rule to enforce access to data:

".write": "root.child('valid_account/'+auth.uid).exists()"

A security rule that allows users to edit their profile but only Forge (admin: true) to create them:

"profiles": {
  "$uid": {
    ".write": "data.exists() && auth.uid === $uid && newData.exists()"
  }
}

Creating your own tokens allows complete control

If you're terribly OCD and don't like that approach, then you can cut out Simple Login. As stated previously, it just creates tokens on your behalf. So simply create your own.

In this way you have complete control over account creation and token generation.

这篇关于Firebase简单登录 - 防止新用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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