【发布时间】:2020-07-13 19:08:36
【问题描述】:
在我的 Firebase 实时数据库中,我有如下所示的评论和回复结构。
{
"post-comments": {
"$postId": {
"pushKey1": {
"uid": "uid1",
"text": "comment 1",
"replies": {
"pushKey2": {
"uid": "uid2",
"text": "reply 1",
"replies": {
... and so on
}
}
}
}
}
}
}
所有 cmets 都将公开阅读。我想编写一个递归安全规则(因为可以有任意数量的嵌套 "replies" 字段),它只允许用户:
- 如果新数据有匹配的
auth.uid和uid字段,则推送 - 如果
auth.uid与现有的uid字段匹配,则更新评论/回复 - 删除将通过软删除处理,因此与更新基本相同
这可能吗?我做了一些谷歌搜索,这个链接作为搜索结果出现:https://firebase.google.com/docs/rules/rules-behavior#recursive_wildcards,但页面的那个部分似乎不再存在。这个功能还存在吗?还是有其他方法可以做到这一点?如果这很重要,我将在客户端与 React 一起使用。
【问题讨论】:
-
该文档页面指的是 Firestore,它的规则系统与实时数据库不同。
标签: firebase firebase-realtime-database firebase-security