适用于某些文档的Firebase Cloud Firestore安全规则

时间:2020-11-02 21:04:15

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

这是我的数据库结构:

用户(集合)->用户文档(uid)-> 愿望清单(集合)->愿望清单文档-> wünsche ->wünsche-docs

user-document的字段username应该对所有人(不是授权用户)可读。除此之外,所有文档和字段都只有在获得用户授权的情况下才可读。

wünsche-document的字段isReservedFrom对于授权的每个用户都应该是可写的。对于所有其他字段/文档,用户只能编写自己的文档。

现在这就是我所拥有的:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read;
      allow write: if request.auth != null;
    }
  }
}

这不是很安全,也不完全是我想要的东西,但是我不知道该如何为我的确切目的进行更改。乐于助人!

如果不清楚,请告诉我!

更新

这是我尝试过的:

authorized的所有人都可以write所有文档和read。每个人都只能usersreadable。但是我在这里弄乱了syntax ...

service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
  allow write: if request.auth != null;
}
match /{users} {
    allow read;
}
match /{users}/documents/{allSubcollections=**} {
    allow read: if request.auth != null
}
}
}

0 个答案:

没有答案