firebase实时数据库:安全规则中的拆分方法:错误保存规则 - 第6行:没有这样的方法/属性' split'

发布于 2025-01-25 17:03:34 字数 740 浏览 3 评论 0原文

我在实时数据库中存储用户消息: < user_1_uid> __< user_2_uid> 现在,在创建对象之前,我正在对其进行整理,以确保对于两个用户,密钥始终匹配。

我希望用户只有在通过__拆分键时才能读取/写消息。

例如:

uid1__UID2聊天只能访问uid1uid2,而没有其他人。

一种方法可能是:$ uidcombo.contains(auth.uid),但对于用例,这将失败: UID11_UID2 UID11UID1都可以访问消息。

我的主要问题是,在火中,我在提议中看到了拆分方法:

"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:
enter image description here

"messages": {
        "$uidcombo": {
          ".read":"$uidcombo.split('__').contains(auth.uid)",
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾`听者〃 2025-02-01 17:03:34

根据字符串类型在安全规则中,它,不支持拆分方法。因此,规则编辑器使用它显示的是自动完成者中的一个错误。

为了实现您的目标,您可以使用beginswithendswith来测试UID。

".read":"$uidcombo.beginsWith(auth.uid+'__') || 
         $uidcombo.endsWith('__'+auth.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 and endsWith to test for the UID.

".read":"$uidcombo.beginsWith(auth.uid+'__') || 
         $uidcombo.endsWith('__'+auth.uid)"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文