Firebase 规则(实时数据库)。检查帖子标题是否包含用户ID

问题描述 投票:0回答:1

我的帖子包含用户 ID,例如,用户 ID 为“abcd1234z”的用户将拥有名为“abcd1234z-1”的帖子。如果帖子标题 ($child) 名称中包含 userId,我无法获得写入规则检查。我尝试了 .contains 和 .matches 选项,但不能正确格式化正则表达式。

{
  "rules": {
    "cloud": {
      "news": {
        ".read": "auth.uid != null",
        ".write": "auth.uid != null",
      }
    },
    "forum": {
      "posts": {
        "$child": {
          ".read": "auth.uid != null",
          ".write": "auth.uid != null && $child.matches(/*+request.auth.uid/)"
          "$uid": {
            ".write": "auth.uid != null && $uid === auth.uid",
          }
        }
      }
    }
  }
}
regex firebase firebase-realtime-database firebase-security
1个回答
1
投票

我最近用

.contains
而不是匹配来测试了这个,并且有效,所以看看 这个问题 和我评论中的屏幕截图。在你的情况下,它应该是这样的:
$child.contains(auth.uid)


更新:我的评论/屏幕截图(现已删除)问题:

这似乎对我有用:
您能展示一下您的案例中哪些内容不起作用吗?

© www.soinside.com 2019 - 2024. All rights reserved.