firebase - 在谷歌云中的安全规则之后,cluase 在哪里不起作用
问题描述
这是我的 firebase 安全规则,它抛出了查询权限:
app.firestore().collection('users').where('email', '==' ,'test@gmail.com').get().then(snap => console.log(snap.docs[0].data())).catch(err => console.log("err",err));
上面的查询抛出权限错误!!
service cloud.firestore {
match /databases/{database}/documents {
// Make sure the uid of the requesting user matches name of the user
// document. The wildcard expression {userId} makes the userId variable
// available in rules.
match /users/{userId} {
allow read, update, delete: if request.auth.uid == userId;
allow create: if request.auth.uid != null;
}
}
}
为什么 ?
解决方案
您的安全规则是说用户只能在 id 与其经过身份验证的 UID 相同的用户中读取文档。但是您的查询正在尝试读取电子邮件字段具有某些价值的任何文档。由于该查询可能会尝试读取与 UID 匹配的文档以外的文档,因此每次查询都会失败。使用您现在拥有的规则,客户端只能获取()他们自己的特定文档,不允许其他查询。
推荐阅读
- sh - 如何在命令行上从 PGP 密钥中提取图像?
- android - 从画中画窗口中打开的通知启动 Intent
- c - 如何使用 select() 进行非阻塞聊天?
- data-structures - 压缩循环数据?
- ruby-on-rails - 你把 ActiveRecord 回调类放在哪里?
- asp.net-core - 使用 ASP.NET Core 2 身份验证时如何获取 LoginPath?
- ios - 在objectiveC中获取和设置NSUserActivity
- javascript - .toLowerCase() of undefined 在后台静默失败 - 但代码仍然可以正常工作
- string - Netlogo:如何从文本字符串中制作单个字符的列表?
- excel - Excel VBA:如何返回给定单元格的列号