handsome
handsome

Reputation: 2432

Firebase rule to allow write only for children

I want to allow the family creator to add children. I´m saving the uid as the "owner" of the family

match /families/{family} {
  allow create: if request.auth != null
  allow update: if request.auth != null && request.auth.uid == request.resource.data.uid;
}

match /families/{family}/children/{child} {
    allow read
    allow create: if request.auth.uid != null //this will allow any parent to create children on any famly!!;
}

how can I allow create if {family}.uid == request.auth.uid ??

Upvotes: 0

Views: 174

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317958

You will need to use get() to access other documents other than the one being matched by the rule. For your case, that means you need to get() the family document in order to use its field values.

match /families/{family}/children/{child} {
    allow read;
    allow create: if
      get(/databases/$(database)/documents/families/$(family)).data.uid == request.auth.uid;
}

Upvotes: 2

Related Questions