Bernhard
Bernhard

Reputation: 269

firebase security-rules write access to only one specific field

is it possible to give update access to only one specific field ?

users
  + gaglajasdfer32fasfa
    - Name: Luke     // not allowed to update
    - likes: 3       // allowed to update

Upvotes: 0

Views: 23

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50830

You will have to specify the rule for each field in that case as shown below:

{
  "rules": {
    "users": {
      "$uid": {
        "Name": {
         ".write": "!data.exists()"
        }
      }
    }
  }
}

!data.exists() allows write operation only when it's absent now and hence allowing "Create" operations only and not "update" or "delete".

Checkout the documentation to learn more about security rules.

Upvotes: 2

Related Questions