首页 > 解决方案 > “错误: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);
  }

标签: reactjsfirebasegoogle-cloud-firestore

解决方案


您的问题是显示 Firestore 的规则,但代码正在访问实时数据库。它们是完全不同的数据库系统,具有不同的规则系统和没有共同点的 API。您将需要检查并更新实时数据库的规则(或更改您的代码以查询 Firestore)。

我可以告诉您的代码正在使用 RTDB,因为调用firebase.database(). firebase.firestore()如果您实际上是在尝试查询 Firestore,您将希望使用它。


推荐阅读