在React本机移动应用程序中集成firestore时获取"firestore/permission-denied"

Afs*_*ara 4 javascript firebase react-native google-cloud-firestore

我正在尝试通过本机应用程序反击来存档文档,但面临以下问题

这是代码

constructor() {
    super();
    this.ref = firebase.firestore().collection('todos');
  }
Run Code Online (Sandbox Code Playgroud)

我们正在触发按钮点击

addTodo() {
      this.ref.add({
        title: this.state.textInput,
        complete: false,
      });
    }
Run Code Online (Sandbox Code Playgroud)

我们正面临这个问题

错误:Firestore:调用方无权执行指定的操作.(公司的FireStore /权限被拒绝).错误:Firestore:调用方无权执行指定的操作.(公司的FireStore /权限被拒绝).

Fra*_*len 8

如果在运行addTodo()它时发生此错误,则表示用户无权写入todos集合.通过服务器端安全规则来控制对Firestore数据的访问.

简单地允许任何人编写以todos使用如下规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /todos/{document=**} {
      allow read, write: if true;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但我强烈建议您阅读文档,以便编写符合应用需求的更安全的规则.