reactjs - “错误:permission_denied at /place:客户端无权访问所需数据。” 在 Cloud FireStore 中
问题描述
我知道这很可能是一个“规则”问题,并且已经尝试了多种解决方法但没有成功……以下是我的规则。
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true
}
}
}
这是我调用数据的 React 组件:
componentDidMount(){
console.log('mounted');
let database = firebase.database();
var ref = database.ref('place')
console.log(ref)
ref.on('value', gotData, errData);
function gotData(data){
console.log(data);
}
function errData(err){
console.log('Error');
console.log(err);
}
解决方案
您的问题是显示 Firestore 的规则,但代码正在访问实时数据库。它们是完全不同的数据库系统,具有不同的规则系统和没有共同点的 API。您将需要检查并更新实时数据库的规则(或更改您的代码以查询 Firestore)。
我可以告诉您的代码正在使用 RTDB,因为调用firebase.database()
. firebase.firestore()
如果您实际上是在尝试查询 Firestore,您将希望使用它。
推荐阅读
- python - 我们如何在 Python 3 中以后续方式附加列表?
- spring-boot - 如何使用 --insecure 或 -k 限制/禁用 curl,基本上,限制证书验证的跳过
- r - 按组随机删除观察百分比
- javascript - TypeError:无法读取未定义的属性“第一个”
- java - 未命名模块从 slf4j.log4j12 和 log4j 读取包 org.apache.log4j
- angular - Angular动态表单改变了一个子组件的值,而另一个子组件的值也改变了
- javascript - ““从不”类型上不存在属性“名称”
- sql - 基于列值在 SQL 中将行作为列名
- python - 我对 Python 的目录、虚拟环境和文件处理完全感到困惑
- r - 我可以控制 as_tibble 或 as.data.frame 如何处理 R 中的一维数据吗?