我很难为Firestore中的多个组和用户设置最佳解决方案。
在下面您可以看到到目前为止的结构和规则,并且在一个小组要按名称列出所有成员之前,它运作得很好,应该如何设置规则?
或者您为我的设置推荐其他结构吗?
users: [
"userId" {
"name" : "Name",
"groups" : ["groupId", "groupId", "groupId"]
}
]
groups: [
"groupId" {
"name" : "Name",
"members" : ["uid1", "uid2", "uid3"]
}
]
contacts: [
"contactId" {
"name" : "Name",
"owner" : "groupId"
}
]
Firestore规则
function member(groupId) {
return request.auth.uid in get(/databases/$(database)/documents/groups/$(groupId)).data.members;
}
match /users/{userId} {
allow read; // <--- how to allow only same group members to read?
allow write: if request.auth.uid == userID;
}
match /groups/{groupId} {
allow read: if request.auth.uid in resource.data.members;
allow write: if request.auth.uid in resource.data.admins;
}
match /contacts/{contactID} {
allow read: if member(resource.data.owner);
allow write: if member(request.resource.data.owner);
}