在具有路径“组织”的Firebase Firestore集合中,每个文档都包含可以更新或删除该文档的用户的字符串userID列表。
export interface Organization{
name?: string,
owners: string[]
}
我想创建一个Firebase安全规则,确保只有具有此列表中的uid的登录用户才能编辑或删除该对象。不确定适当的语法。
service cloud.firestore {
match /databases/{database}/documents {
match /organizations/{organization} {
allow read: if true;
allow create: if request.auth != null;
/// What should be the syntax here?
allow update, delete: if request.auth != null && (request.auth.uid in resource.data.owners); // <--------- What should be the syntax for this line?
}
好的,在这里回答我自己的问题,以防它对其他人有用。
看起来上面的'in'语法实际上是有效的 - 尽管它是一个完整的猜测,我无法在firebase安全角色文档中找到它的任何文档。
最终代码:
service cloud.firestore {
match /databases/{database}/documents {
match /organizations/{organization} {
allow read: if true;
allow create: if request.auth != null;
allow update, delete: if (request.auth != null) && (request.auth.uid in resource.data.owners);
}