Skip to content
Advertisement

Getting ‘firestore/permission-denied’ while integrating firestore in React native mobile app

I’m trying to firestore documents through react native app, but facing the following issue

Here is the code

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

and we are triggering button click

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

we are facing this issue

Error: Firestore: The caller does not have permission to execute the specified operation. (firestore/permission-denied). Error: Firestore: The caller does not have permission to execute the specified operation. (firestore/permission-denied).

Advertisement

Answer

If this error occurs when you run addTodo() it means that the user doesn’t have permission to write to the todos collection. Access to Firestore data is controlled through its server-side security rules.

To simply allow anyone to write to todos use a rule such as this:

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

But I highly recommend you read the documentation so that you can write more secure rules that match the needs of your app.

Advertisement