1 回答
TA贡献1803条经验 获得超6个赞
您的问题似乎来自您阅读sub-collections 中的文档这一事实。
让我们以集合为例topsection。您有如下安全规则:
match /topsection/{id} {
allow read: if true;
allow write: if request.auth.uid != null;
}
但是您查询文档如下:
getTopSectionMain() {
return this.firestore.collection('topsection').doc('content').collection('main').snaps hotChanges();
}
这意味着您查询集合中文档的main子集合的content文档topsection。
如文档中所述:“安全规则仅适用于匹配的路径,因此在(父)集合上定义的访问控制不适用于(子)子集合。”
您需要通过添加递归通配符来调整规则
match /topsection/{document=**} {
allow read: if true;
allow write: if request.auth.uid != null;
}
或指定每个子集合,如:
match /topsection/{id} {
match /main/{id} {
allow read: if true;
allow write: if request.auth.uid != null;
}
}
由于您没有使用通配符来声明顶级集合的安全规则,因此您最好使用第二个选项。
添加回答
举报
