【问题标题】:Could someone please help me write the rule for the Firebase data structure below?有人可以帮我写下 Firebase 数据结构的规则吗?
【发布时间】:2022-01-27 22:35:06
【问题描述】:

我想在 firebase 中编写一条规则,以在禁用设置为 false 时仅允许用户写入数据库。

我的数据库结构如下:

{
  "Users": {
    "UID": {
      "details": {
        "random key generated by push": {
          "disable": true,
        },
      }

非常感谢您的帮助!干杯!

【问题讨论】:

    标签: firebase-realtime-database firebase-security


    【解决方案1】:

    要从安全规则内的另一个节点读取值,您必须知道该节点的确切路径。因此,除非您知道 "random key generated by push" 的值,否则无法从其上方节点之一的规则中读取它。


    这通常意味着您应该更改您的数据结构以在 UID 节点下的已知位置具有 disable 标志。例如:

    {
      "Users": {
        "UID": {
          "disable": true,
          "details": {
            "random key generated by push": {
            },
          }
    

    现在您可以像这样允许访问 UID 节点:

    {
      "rules": {
        "Users": {
          "$uid": {
            ".read": "data.child('disable').val() === true"
          }
        }
      }
    }
    

    【讨论】:

    • 感谢朋友的回答。它解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 2017-11-30
    相关资源
    最近更新 更多