Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this firebase rule redundant? When to use write vs validate?

I read through the docs, and I'm not sure of the difference between the write-rule and validation-rule section. Is this code redundant? Any point of using one or the other, or both?

Specifically:

  • "validates" to say "user must be logged in, and the value written must be the uid.
  • "write" permission says you can only write to the $user_id section if the value matches your uid.
{
  "rules": {
    "users": {
      ".validate": "auth != null && newData.val() === auth.uid",
      "$user_id": {
        ".write": "$user_id === auth.uid"
      }
    }
  }
}
like image 818
Benjamin H Avatar asked Feb 16 '16 17:02

Benjamin H


1 Answers

The only difference is that .validate doesn't propagate to its children.

Answering to your question, in your example you could use just ".write".

".write": "auth != null && $user_id === auth.uid"

like image 95
Seb Avatar answered Nov 11 '22 13:11

Seb