【发布时间】:2020-01-15 02:52:50
【问题描述】:
我正在开发一个我想在 firebase 实时数据库上运行的项目。我用这种格式创建了一个数据库设置:
{
"Horses" : {
"description" : "",
"id" : "",
"name" : "",
"uid" : "testx"
},
"images" : {
"full_path" : "",
"horse_id" : "",
"id" : "",
"thumbnail_path" : "",
"uid" : ""
},
"videos" : {
"full_path" : "",
"horse_id" : "",
"id" : "",
"thumbnail_path" : "",
"type" : "",
"uid" : ""
}
}
我的安全规则如下所示:
{
"rules": {
"Horses":{
".read": true,
".write": false,
"$uid":{
".read": true,
".write": "$uid == auth.uid"
}
},
"videos":{
".read": true,
".write": false,
"$uid":{
".read": true,
".write": "$uid == auth.uid"
}
},
"images":{
".read": true,
"$uid":{
".read": true,
".write": "$uid == auth.uid"
}
},
}
}
我正在尝试归档每个人都可以阅读“马”、“图像”和“视频”中的详细信息,但只有经过身份验证的用户才能将条目添加到“马”、“图像”和“视频”中,如果它们属于他们自己(由 firebase auth 提供的用户 ID 检查)。
我的第一个问题是:我是否应该将“图像”和“视频”作为“马”的子对象包含在内?如果我可以一次为 Horse 编写一个读写规则,它会级联到其他规则,那就更好了。
我的第二个问题是:即使身份验证设置为与我写入的数据相同的 uid,我也无法将集合写入马或图像。例如,我似乎必须将我的请求发送到horses/[UID-HERE]。我如何编写将我描述的行为归档的规则?
感谢您的帮助!
【问题讨论】:
-
在你的例子中你没有错过每个节点下的一个键吗?
标签: firebase firebase-realtime-database firebase-authentication