您如何在Firebase上阻止用户? [英] How do you block users on Firebase?
问题描述
我正在为我的应用程序使用Firebase,并且想知道如何阻止某些用户.我在控制台的身份验证"选项卡上看到,有删除"和禁用"选项.这些是做什么的?我一直无法找到有关的文档.其中一个可以允许我阻止用户吗?
I'm using Firebase for my app and was wondering how to block certain users. I see on the Auth tab of the console, there are "delete" and "disable" options. What do those do? I haven't been able to find documentation on that. Will one of those allow me to block a user?
我所说的阻止用户是为了".read": "auth != null"
规则,以防止用户访问数据库中的数据
What I mean by blocking a user is for the ".read": "auth != null"
rule to prevent him from accessing data on the database
推荐答案
禁用功能在于阻止该用户进行身份验证.因此,如果他尝试进行身份验证,则将失败,并显示错误代码INVALID_CREDENTIALS
,并且他将无法访问具有".read": "auth != null"
规则的数据.就像他被删除一样,但管理员仍然可以重新激活用户帐户.
The disable feature consist in preventing that user to authenticate. So if he tries to authenticate he will fail with error code INVALID_CREDENTIALS
and he won't have access to the data that has the ".read": "auth != null"
rule. It works like he is deleted but the admin still have the power to reactivate the user account.
如果您要构建可进行身份验证但具有受限访问权限的被阻止的用户"列表,则可以将被阻止的ID存储在Firebase数据库的节点中,例如security and rules
.
If you want to build a list of "blocked users" that will be able to authenticate but will have restricted access, you can store the blocked ids in a node on your firebase database like /databaseRoot/blockedUsers
and then work with the security and rules
.
".read": "auth != null && !root.child('blockedUsers').hasChild(auth.uid)"
blockedUsers 看起来像下面的树,但是您也可以在userId下添加一些其他信息,例如该用户被阻止的日期.
blockedUsers could look like the tree bellow but you could also add some other info under the userId such as the date this user was blocked.
/databaseRoot
/blockedUsers
userId1 : true
userId2 : true
将用户添加到此列表将取决于您的需要.您可以通过访问Firebase控制台并将用户ID添加到节点来手动完成此操作.或者,如果您想基于应用程序上的事件来阻止用户,则可以简单地调用
Adding the user to this list will depend on your necessity. You can do it manually by accessing the firebase console and adding the user id to the node. Or, if you want to block an user based on an event on the application, you could simply call something like
ref.child('blockedUsers').child(userIdToBlock).set(true);
这篇关于您如何在Firebase上阻止用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!