prevent “delete and update” a child in firebase

南笙酒味 提交于 2019-11-28 09:33:47

问题


I see that there is no way to set security rules as preventing "delete and update" for a child.

".write": "!data.exists() && newData.exists() && !newData.exists()"

thats not make sense.


回答1:


For future reference, the Firebase console lets you test database security rules, so you can find out what works right there before you publish those rules. That being said, if I'm understanding your question correctly, you want to allow users to add to the node, but not delete or update. You'd be looking for something along the lines of:

{
  "rules": {
    ...

    "childNodeName": {
       ".write": "!data.exists()"
    }
  }
}

You shouldn't need those other two conditions. Not to mention, they will never resolve to true since those conditions cannot be met.

You can also use a wildcard if you need to add multiple children to a path but you don't want the user to modify those children once they've been added:

{
  "rules": {
    ...

    "childNodeName": {
       "$pushId": {
          ".write": "!data.exists()"
      }
    }
  }
}  


来源:https://stackoverflow.com/questions/44115776/prevent-delete-and-update-a-child-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!