【发布时间】:2021-07-14 10:39:43
【问题描述】:
我正在尝试为我的应用设置 firebase 数据库规则。本质上,该应用程序有一个帖子页面,允许用户与不同的帖子进行交互。
我遇到的问题是,当我尝试在“$post_id”分支下设置规则时,我的应用程序中没有数据加载,我有一个连续加载屏幕。但是如果我从规则中删除这个“$post_id”分支,那么我的应用程序会正确加载。
我的数据库看起来像这样。如您所见,帖子是在自动 ID 节点下加载的,这就是我尝试添加 $post_id 以反映这一点的原因。
{
"rules": {
"posts": {
// the key for each post is stored inside $post_id variable for reference
"$post_id": {
// general rules
".indexOn": ["timestamp", "likes"],
".read": "auth != null",
// enter the author branch
"author": {
".read": "auth != null",
"$user_id": {
".write": "$user_id === auth.uid"
}
},
//enter the comments branch
"comments": {
".indexOn": ["timestamp"]
}
}
}
【问题讨论】:
标签: firebase-realtime-database firebase-security rules