【发布时间】:2018-09-03 16:18:48
【问题描述】:
我有一个这样的数据库架构:
- 帖子
- 未验证
- post_1
- post_2 ...
- 未验证
这是 /posts/unverified 路径中数据的缩短列表
{
"-L7xmY2HMeEImDZnZqTf" : {
"categorie" : 0,
"commonFields" : {...},
"fbKey" : "-L7YM7vEf8RpcxGUTpDE",
"images" : [...],
"specialFields" : {
"area" : "150",
"productPrice" : {
"currency" : "dollar",
"value" : "65000"
},
"requestType" : "sell",
"requesterType" : "personal",
"roomCount" : 3,
"suburbia" : "false"
},
"subCat" : 0,
"timestamp" : 1521011840178,
"uid" : "Fo5f6VonWgQVpsf6u80TPgoi2it2"
},
"-L7YNUZPL1-Dl7EhScEE" : {...},
"-L7YNUZPL1-fdfasfa" : {...},
"-L7YNUZPL1-ljljklfd" : {...},
"-L7YNUZPL1-lkjlkjfas" : {...},
}
还有一个firebase安全规则定义如下
{
"rules": {
"posts": {
"unverified": {
".indexOn": "timestamp",
".read": "data.child('uid').val() === auth.uid"
如规则所示,如果用户 id 等于帖子数据中的 uid 字段,我想阅读未经验证的帖子
但是每次我使用以下配置的规则模拟器(或使用代码测试)时,它都会给出Simulated read denied 错误
感谢您的帮助
【问题讨论】:
-
请编辑您的帖子以在
/posts/unverified显示实际的 JSON(作为文本,无屏幕截图)。您可以通过单击 Firebase Database console 中的“导出 JSON”链接来获取此信息。 -
我刚刚更新了弗兰克的帖子..
-
该帖子没有您正在测试的 UID 的
uid属性。那确实会使模拟器失败。 -
它确实有一个与 UID 完全一致的 uid 我正在测试。这就是为什么我在这里问。即时消息测试有一个键
-L7xmY2HMeEImDZnZqTf并且该帖子具有 uid 属性Fo5f6VonWgQVpsf6u80TPgoi2it2.. 我用Fo5f6VonWgQVpsf6u80TPgoi2it2uid 测试posts/unverified/-L7xmY2HMeEImDZnZqTf路径 -
啊等等,我现在看到了。您的规则中缺少一个级别。我会在答案中写一个例子。
标签: firebase firebase-realtime-database firebase-security