【问题标题】:Firebase realtime database security rule get child nameFirebase 实时数据库安全规则获取子名称
【发布时间】:2019-03-14 00:31:05
【问题描述】:

有没有办法让我得到一个孩子的名字?结构是这样的:

appointment-
           |- "here_is_some_date"-
                                 |-"some_user_id"-
                                                 |-details about it

我需要为谁可以阅读“约会”定义一个规则,但我不确定如何获取日期名称,以便获取 UID。这是我尝试过的:

"appointments": {
        ".read": "data.child(data.val()).child(auth.uid).val() === auth.uid"
      }

【问题讨论】:

    标签: firebase firebase-realtime-database firebase-security


    【解决方案1】:

    在 Firebase 安全规则中读取子节点值的唯一方法是,如果您知道从当前节点(定义规则的位置)到子节点的确切路径。

    因此,如果您知道日期和 UID(您肯定知道),您可以通过以下方式读取子节点的值:

    "appointments": {
      ".read": "data.child('here_is_some_date').child('some_user_id').val() === auth.uid"
    }
    

    但是没有办法在这条路径中使用通配符。很难说你到底想要实现什么用例,但如果它是“允许用户阅读他们有约会的约会日期”,那么这将需要一个额外的、倒置的数据结构:

    "user_appointment_dates": {
      "uid1": {
        "date1": true // or a more complete structure with the actual appointments
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-08-08
      • 2020-12-28
      • 2021-10-26
      • 2021-02-13
      • 2018-08-27
      • 2021-02-11
      • 2021-12-05
      • 2020-07-11
      相关资源
      最近更新 更多