Ios 在Firebase数据库中创建节点后,如何防止访问更改?

Ios 在Firebase数据库中创建节点后,如何防止访问更改?,ios,firebase,firebase-realtime-database,firebase-security,Ios,Firebase,Firebase Realtime Database,Firebase Security,在以下情况下,如果节点已经存在,如何拒绝更新(覆盖)该节点的访问?例如,请求添加到朋友,我想,这个功能执行了一次,因为它在数据库中设置了规则,但它们不起作用。如何解决这个问题 规则 资料 更新 我认为问题出在这个代码中,因为我在规则中也有这个代码。但是我怎样才能修复它呢 "rules": { ".read": "auth != null", ".write": "auth != null", } 更新1:以下是所有规则。我只需要在friends中创建一个特定的写入规则(更新)

在以下情况下,如果节点已经存在,如何拒绝更新(覆盖)该节点的访问?例如,请求添加到朋友,我想,这个功能执行了一次,因为它在数据库中设置了规则,但它们不起作用。如何解决这个问题

规则

资料

更新 我认为问题出在这个代码中,因为我在规则中也有这个代码。但是我怎样才能修复它呢

"rules": {
    ".read": "auth != null",
    ".write": "auth != null",
 }
更新1:以下是所有规则。我只需要在friends中创建一个特定的写入规则(更新)。我看到了每个分支规则的示例,但是如果我需要为一个分支执行一些特定的规则,而对于数据库的其余部分,您需要标准规则,我应该如何更好地执行这些规则

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null",



      // card location
    "cardLocation": {
      // Allow anyone to read the GeoFire index
      //".read": true,
      // Index each location's geohash for faster querying
         ".indexOn": "g",

     },

      "cards": {
        ".indexOn": "ownerID"
      },

      "userListEvents": {
          "$uid": {
            ".indexOn": "isConfirmed"
          }
      },

      "userImages": {
        "$uid": {
          "userProfileImages": {
                            ".indexOn": "isoDate"
          }
        }
      },

      // tags 
      "userTags": {
        "$uid": {
          ".indexOn": "isSelected"
        }
      },


        // people search
        // 
        "userLocations": {
          ".indexOn": "g"
        },


      // friends 
      "friends": {
        "$ownerID": {
          "friendIncomingRequests": {
            "$secondUserID": {
              ".write": "!data.exists()" 
            }
          },
          "friendOutgoingRequests": {
             "$secondUserID": {
              ".write": "!data.exists()" 
            }
          }
        }
      }

  }
}
我认为问题出在这个代码中,因为我在规则中也有这个代码。但是我怎样才能修复它呢

"rules": {
    ".read": "auth != null",
    ".write": "auth != null",
 }
是的,你的想法是正确的。Firebase
。读取
。写入
规则级联。因此,您应该在数据结构的每个子节点上放置每个
.read
.write
。诸如此类:

{
  "rules": {
  //skip this
    "someNode": {
        ".read": "auth != null",
        ".write": "auth != null"
    },
    // friends 
    "friends": {
      "$ownerID": {
        "friendIncomingRequests": {
          "$secondUserID": {
           ".write": "!data.exists()" 
        }
      },
        "friendOutgoingRequests": {
          "$secondUserID": {
            ".write": "!data.exists()" 
          }
        }
      }
    }
    //...
  }
}

我很感激更新,但我有点困惑。你能在顶部的原始规则中添加额外的规则吗?这样我就可以准确地看到它的外观了?我想我可能有一个解决方案给你,但澄清会有帮助。@JenPerson你好!我写了所有的数据库规则。请看一看。非常感谢你!非常感谢。哦,还有一件事:当你说它不起作用时,你的意思是在测试中。写总是被允许的,还是永远不被允许的?@JenPerson,我的意思是,它总是被允许的。我想为特定的分支设置特定的规则。(例如对朋友的请求)。谢谢。是的,我这样做了,我只是想也许有更好的办法,把一个分支作为例外。答案对孩子们来说也不例外:D
"rules": {
    ".read": "auth != null",
    ".write": "auth != null",
 }
{
  "rules": {
  //skip this
    "someNode": {
        ".read": "auth != null",
        ".write": "auth != null"
    },
    // friends 
    "friends": {
      "$ownerID": {
        "friendIncomingRequests": {
          "$secondUserID": {
           ".write": "!data.exists()" 
        }
      },
        "friendOutgoingRequests": {
          "$secondUserID": {
            ".write": "!data.exists()" 
          }
        }
      }
    }
    //...
  }
}