我有一组邀请,并且权限不足错误。
"inviteID" : {
playerEmail: '[email protected]',
teamID: 'abcdefg'
}
和一个团队
"teamID" : {
...
managers: [managerID, ...]
...
}
带有以下查询:
查询似乎很简单
db.collections('invites').where('teamID', '==', myTeamID)
但是规则必须检查所查询的人是否是经理...
match /invites/{inviteID} {
function isManager() {
// managers is an array
return get(/databases/$(database)/documents/teams/$(resource.data.teamID)).data.managers.includes(request.auth.uid)
}
allow read: if (isManager())
}
我也有此规则会失败吗?
// Allow user to read his own invites
match /invites/{inviteID} {
allow read: if (request.auth.token.email == resource.data.playerEmail)
}
与同一文档匹配的第二条规则将失败,因为显然邀请者将没有与管理者相同的电子邮件。我需要此规则,因为单独的查询允许用户查询其邀请。
似乎无法阅读,我遇到了权限问题。感谢帮助!
所以我将规则更改为
return request.auth.uid in get(/databases/$(database)/documents/teams/$(resource.data.teamID)).data.managers
这似乎解决了我的权限错误