Firebase规则仅允许孩子写

时间:2020-04-21 17:09:15

标签: firebase google-cloud-firestore firebase-security

我想允许家庭创建者添加孩子。我将uid保存为家庭的“所有者”

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!!;
}

如果{family} .uid == request.auth.uid?

1 个答案:

答案 0 :(得分:1)

您将需要use get() to access other documents而不是该规则所匹配的那个。对于您的情况,这意味着您需要get()系列文档才能使用其字段值。

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