[英]Why do I get an insufficient permissions error while trying to delete an array element from firestore, yet I can delete the entire document
I have a collection in my firestore named "reports"我的firestore中有一个名为“reports”的集合
one of the fields in the reports map is an array of objects.报告映射中的一个字段是对象数组。 These objects reference a photo in cloud storage.这些对象引用云存储中的照片。 They look like this (url points to cloud storage):它们看起来像这样(url指向云存储):
{
id: uid value
url: some-url
}
my firebase rules are set up like this for the reports document:我的 firebase 规则为报告文档设置如下:
match /databases/{database}/documents {
match /reports/{report} {
allow read: if request.auth != null && request.auth.uid == resource.data.userID;
allow create: if request.auth != null && request.resource.data.userID == request.auth.uid;
allow delete, update: if request.auth != null &&
request.auth.uid == resource.data.userID;
}
}
for some reason, I can delete the entire document if I want to proving that I have delete permission.....but when I attempt to delete an item from the photos array like this:出于某种原因,如果我想证明我有删除权限,我可以删除整个文档......但是当我尝试从这样的照片数组中删除一个项目时:
const reportRef = db.collection('reports')
reportRef.doc(activeReport.id).update({
photos: firebase.firestore.FieldValue.arrayRemove(photoToDelete)
})
I end up with an error stating:我最终得到一个错误说明:
Unhandled promise rejection: FirebaseError: Missing or insufficient permissions未处理的承诺拒绝:FirebaseError:权限缺失或不足
Why?为什么? Haven't I given permission to update this document properly?我没有授予正确更新此文档的权限吗?
Go in Database -> Rules ->进入数据库 -> 规则 ->
For development:用于开发:
Change allow read, write: if
false;更改allow read, write: if
假; to true;为真;
Note: It's a quick solution for development purposes only because it will turn off all the security.注意:这是用于开发目的的快速解决方案,因为它会关闭所有安全性。 So, it's not recommended for production.因此,不建议将其用于生产。
For production:用于生产:
If authenticated from firebase: Change allow read, write: if
false;如果从 firebase 进行身份验证: Change allow read, write: if
假; to request.auth != null;到request.auth != null;
In this case it was a bad parameter that was passed in. I needed to pass activeReport not activeReport.id.在这种情况下,传入的是一个错误的参数。我需要传递 activeReport 而不是 activeReport.id。
This is a misleading error message.这是一个误导性的错误消息。 I would delete this question but stackoverflow doesn't want me to because an answer has been posted here.我会删除这个问题,但 stackoverflow 不希望我这样做,因为这里已经发布了一个答案。 Silly.愚蠢的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.