我的帖子包含用户 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",
}
}
}
}
}
}
我最近用
.contains
而不是匹配来测试了这个,并且有效,所以看看 这个问题 和我评论中的屏幕截图。在你的情况下,它应该是这样的:$child.contains(auth.uid)
。
更新:我的评论/屏幕截图(现已删除)问题: