gpt4 book ai didi

javascript - Firestore : Missing or insufficient permissions when trying to add a new subcollection

转载 作者:行者123 更新时间:2023-11-30 19:11:31 26 4
gpt4 key购买 nike

我目前有一些访问我的 firestore 数据库的基本规则。规则详述如下。谁能帮我理解为什么第二段代码会导致权限错误?我正在尝试将图像添加到尚不存在的子集合中。谢谢

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /projects/{project} {
allow read, write: if request.auth.uid != null
}
match /users/{userId} {
allow create
allow read: if request.auth.uid != null
allow write: if request.auth.uid == userId
}
match /notifications/{notification} {

allow read: if request.auth.uid != null

}

}
}

这是我的应用程序代码:

await firestore.add(
{
collection: "users",
doc: user.uid,
subcollections: [{ collection: "photos" }]
},
{
name: imageName,
url: downloadURL
}
);

最佳答案

我对“reduxfirestore”一无所知,但看起来你正试图写入用户下的子集合。您的安全规则对子集合中的文档没有任何规定,因此所有这些查询都将被拒绝。如果您希望能够读写文档,则规则必须匹配它们的完整路径,如下所示:

match /users/{uid}/photos/{pid} { ... }

在控制台中读取和写入始终有效,因为它绕过了安全规则。

关于javascript - Firestore : Missing or insufficient permissions when trying to add a new subcollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58414018/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com