Rakesh Kumar
Rakesh Kumar

Reputation: 79

firebase security rule which will prevent the updation or deletion of existing node

for example, if I have created a node (book) which have a child (author) with value ("name of author"). What I want is that in future no one can update or delete this child node. I know it is possible with firebase security rules but I am not able to figure out the optimal way to do so.

Upvotes: 1

Views: 262

Answers (1)

sketchthat
sketchthat

Reputation: 2688

You could write a database rule to only allow creating new data and not editing anything once it's been written.

This allows you to create a new book if no data already exists at the $key location. It also ensures that newData exists and that author is a string variable.

{
  "rules": {
    "book": {
      "$key": {
        "author": {
          ".validate": "newData.isString()"
        },
        ".write": "data.val() == null && newData.val() != null"
      }
    }
  }
}

Upvotes: 2

Related Questions