firebase - firebase firestore 规则验证了对除一个之外的所有集合的访问权限
问题描述
我有以下firestore结构,基本上是3个集合
公共数据受保护数据1 受保护数据2
我想要protecteddata1和protecteddata 2,实际上整个firestore数据库只作为经过身份验证的用户。但我希望公众拥有对“publicdata”集合的只读访问权限。
以下是我的尝试,但它不起作用
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read;
allow write: if (request.auth.uid != null);
}
match /publicdata {
allow read;
}
}
}
解决方案
这里的递归通配符允许访问所有集合:
match /{document=**} {
allow read;
allow write: if (request.auth.uid != null);
}
一旦任何规则允许访问集合,该访问权限就不能被任何其他规则撤销。
您需要做的是按照自己的规则调用每个单独的集合。是的,这有点痛苦,但这是你唯一的选择。它还使您的规则的读者非常清楚您打算为每个集合允许什么。
另外值得注意的是,这条规则实际上并没有做任何事情,因为它不匹配任何文档:
match /publicdata {
allow read;
}
如果要匹配 publicdata 集合中的文档,则需要一个与该集合中的文档匹配的通配符:
match /publicdata/{id} {
allow read;
}
请记住,规则匹配文档以进行访问,而不是集合。
推荐阅读
- javascript - Azure Blob 静态网站中的乱码
- python - 循环根据多列条件过滤行 pandas python
- linq - 实体框架核心组按日期
- python - 将每个数据帧值复制 n 次
- dictionary - 如何将 JSON 输出保存到字典中?
- python-3.x - Python:python ast 中的 ast.FunctionType 是什么?
- python - 根据现有列中的值创建新列并合并行
- git - Git - 如果新 URL 的 git 历史记录完全不同,如何删除子模块并以相同的名称和路径再次创建它?
- python - 函数的 Sphinx 自动摘要模板在哪里?
- python - 时间序列单变量数据集的异常预测算法