【问题标题】:Getting 'firestore/permission-denied' while integrating firestore in React native mobile app在 React 本机移动应用程序中集成 firestore 时获得“firestore/permission-denied”
【发布时间】:2018-06-18 13:51:43
【问题描述】:

我正在尝试通过 react native 应用程序来存储文档,但遇到以下问题

这里是代码

constructor() {
    super();
    this.ref = firebase.firestore().collection('todos');
  }

我们正在触发按钮点击

addTodo() {
      this.ref.add({
        title: this.state.textInput,
        complete: false,
      });
    }

我们正面临这个问题

错误:Firestore:调用者没有执行指定操作的权限。 (firestore/permission-denied)。 错误:Firestore:调用者没有执行指定操作的权限。 (firestore/permission-denied)。

【问题讨论】:

    标签: javascript firebase react-native google-cloud-firestore


    【解决方案1】:

    如果在运行addTodo() 时出现此错误,则表示用户没有写入todos 集合的权限。通过其server-side security rules 控制对 Firestore 数据的访问。

    要简单地允许任何人写信给todos,请使用如下规则:

    service cloud.firestore {
      match /databases/{database}/documents {
        match /todos/{document=**} {
          allow read, write: if true;
        }
      }
    }
    

    但我强烈建议您阅读documentation,以便您可以编写更安全的规则来满足您的应用需求。

    【讨论】:

      【解决方案2】:

      在 Firestore 中,如果您有任何权限被拒绝。这是因为 Firestore 安全规则。

      在这种情况下,转到您的数据库规则部分并将 if false 更改为 if true

      allow read, write: if true;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-11-27
        • 2022-12-05
        • 1970-01-01
        • 1970-01-01
        • 2021-07-15
        • 1970-01-01
        • 1970-01-01
        • 2020-09-07
        相关资源
        最近更新 更多