firebase - Serious problem Firebase read rule for blocked user
问题描述
I am facing with a serious problem with Firebase security rule. I want to set read
to false to blocked user on search. Here is my database structure.
users:{
uid1:{
name:"Joe",
created:1226287
},
uid2:{
name:"John",
created:1273725
},
uid3:{...},
uid4:{...},
...
},
blocked:{
uid1:{
uid2: true,
uid4: true
}
}
Consider above structure, assume that user2
search a user under users
node by name typing "Joe" and click enter. I set my firebase rule like this.
users:{
$uid:{
".read":"!root.child('blocked').child($uid).hasChild(auth.uid)"
}
}
This rule works fine if user2
query user/user1
path. But when user2
searched, how can I prevent him from getting blocked user data.
解决方案
没有直接的方法可以获取没有阻止该特定用户的用户列表。但是,如果用户根据用户名或其他一些基于用户的标准进行搜索,那么最好的工具是 Firebase Functions。
实现功能的步骤(考虑基于名称搜索)(从客户端调用 firebase 函数并传递搜索名称):
- 获取所有具有相同名称的用户详细信息。
- 获取所有阻止请求用户的用户(或同名用户)。
- 弹出所有阻止请求用户的用户。
- 将用户列表发送回请求的用户。
为什么 Firebase Function 是这种情况下的最佳选择?因为这些功能是在安全的环境中执行的,并且可以绕过安全规则。
推荐阅读
- linux - grep 用于包含“+”的变量
- python - 如何在 django 导入中附加数据?
- html - 如何强制验证禁用的属性?
- python - OSX 的 Cython 链接错误
- tkinter - 如何在无头 jupyter 笔记本服务器上绘制 nltk 树 [尝试了一堆“解决方案”,但没有一个奏效]
- angular - 有没有办法在动态创建的组件中访问 @Input 变量?
- python - 将 Python 脚本添加到 Ruby Gem
- angularjs - 从springboot modelview对象获取值到角度JS 5
- css - 将文本放在微调器引导程序下
- java - 2 个微调器:从使用 Retrofit 选择的第一个微调器 id 填充第二个微调器