当经过身份验证的用户尝试创建具有两个字段的帖子时,这些firebase规则返回拒绝的权限,一个是包含用户id(uid(的authorId
字段,另一个是含有'published' | 'draft'
的editStatus
字段
match /posts/{post} {
allow read: if request.auth != null && resource.data.editStatus == 'published'
|| request.auth.uid == resource.data.authorId;
allow write: if request.auth != null && request.auth.uid == resource.data.authorId;
}
有人能帮我吗?
如果您正在创建新文档,则无法检查resource.data.authorID
,因为此时资源不存在。相反,您将希望查看request.resource.data.authorID
中的请求值。
我还强烈建议将您的安全规则分解为细粒度条件,以尊重地处理创建与更新。
来源:https://firebase.google.com/docs/firestore/security/rules-structure#granular_operations