我在消防局有个“邮件”收藏品。我正在尝试设置安全规则,以便只有所有者作者可以根据字段中的uid访问控制。
/mail/unique_id
{
author: "RPH6j0eZc2QrDhvsQJhDDFApjnj1"
date: "2022-11-23T10:57:13.580Z"
status: "ongoing"
}
消防局规则:
match /mail/{mailId}{
allow read, write: if request.auth != null && request.auth.uid == resource.data.author;
}
功能岗位
this.db.collection('mail').add(data)
从收集邮件中读取
this.db.collection('mail',ref=>ref.where('author','==',this.uid)).get().subscribe(res => { })
结果:我可以从防火墙数据库中读取数据,但是,当我试图推送新的数据时,我会出错。
FirebaseError: [code=permission-denied]: Missing or insufficient permissions.
发布于 2022-11-23 11:23:17
我可以从消防局数据库中读取数据,但是,当我试图推送新数据时,我会出错。
这是因为对于读取规则,您必须使用resource.data
,但是对于写规则,您需要使用request.resource.data
。
所以你需要分成两条规则:
match /mail/{mailId}{
allow read: if request.auth != null && request.auth.uid == resource.data.author;
allow write: if request.auth != null && request.auth.uid == request.resource.data.author;
}
文档中的更多细节。
https://stackoverflow.com/questions/74545826
复制相似问题