firebase实时数据库:安全规则中的拆分方法:错误保存规则 - 第6行:没有这样的方法/属性' split'
我在实时数据库中存储用户消息: < user_1_uid> __< user_2_uid>
现在,在创建对象之前,我正在对其进行整理,以确保对于两个用户,密钥始终匹配。
我希望用户只有在通过__
拆分键时才能读取/写消息。
例如:
uid1__UID2
聊天只能访问uid1
和uid2
,而没有其他人。
一种方法可能是:$ uidcombo.contains(auth.uid)
,但对于用例,这将失败: UID11_UID2
UID11
和UID1
都可以访问消息。
"messages": {
"$uidcombo": {
".read":"$uidcombo.split('__').contains(auth.uid)",
}
I am storing user messages in real time database like this:<USER_1_UID>__<USER_2_UID>
now before creating the object, I am sorting it so to ensure that for two users the key always matches.
I want a user to be able to read/write the messages only if the key when split through __
contains the uid of the user that requested it.
For example:
uid1__uid2
chat must only be accessible to uid1
and uid2
and no one else.
One method could be: $uidCombo.contains(auth.uid)
but this will fail for the use case:uid11_uid2
where both uid11
and uid1
would be able to access the messages.
My major question is does split method exist in firebase as I see it in suggestions:
"messages": {
"$uidcombo": {
".read":"$uidcombo.split('__').contains(auth.uid)",
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据字符串类型在安全规则中,它,不支持
拆分
方法。因此,规则编辑器使用它显示的是自动完成者中的一个错误。为了实现您的目标,您可以使用
beginswith
和endswith
来测试UID。According to the reference documentation for the String type in security rules, it does not support a
split
method. So it seems like a bug in the auto-completer that the rules editor uses that it shows that.To achieve your goal, you could use
beginsWith
andendsWith
to test for the UID.