Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 816
Afsara Avatar asked Jan 09 '18 13:01

Afsara


People also ask

How do I access my firestore database in react?

Select the default Firestore location and click to enable your database. Continue configuring your Firebase by adding the Firebase web SDK to our React app. To do this, click on the web icon on your project overview screen. Your next prompt will require you to add Firebase to your web app.


1 Answers

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.

like image 126
Frank van Puffelen Avatar answered Oct 06 '22 06:10

Frank van Puffelen