Error while creating Documents on Cloud Firestore - Permission Denied

Viewed 1303

I am trying out Cloud Firestore. I think I have done something silly, so I am not able to even to create any docs/collection, both through code and through console.

I haven't locked the DB with any write/read rules (any one can read/write) to the DB. Below is my rule configuration.

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

When I try through console, it opens up a modal where I enter the collection name and the first document (using generated ID). Then clicking on 'Save' simply closes the modal, but the DB is not updated.

When I try to insert docs through code (JS), I could see the following error thrown on the console.

Error updating data: Error: PERMISSION_DENIED: Permission denied
at firebase-storage.js:3479
at z (firebase-storage.js:3479)
at t.callOnCompleteCallback (firebase-storage.js:3479)
at firebase-storage.js:3479
at firebase-storage.js:3479
at e.ci (firebase-storage.js:3479)
at t.ci (firebase-storage.js:3479)
at t.qi (firebase-storage.js:3479)
at e.onMessage (firebase-storage.js:3479)
at e._o (firebase-storage.js:3479)

Below is the JS code.

var config = {
  apiKey: "xxxx",
  authDomain: "xxxx.firebaseapp.com",
  databaseURL: "https://xxxx.firebaseio.com",
  projectId: "xxxx",
  storageBucket: "",
  messagingSenderId: "yyyy"
};
firebase.initializeApp(config);

var db = firebase.firestore();

$scope.addNote = function() {

  var note = {
    text: 'Sample Note',
    createdBy: 'Ranis'
  }
  db.collection('notes').add(note).then(function(data) {
      console.log('Note Added ', data)
    },
    function(err) {
      console.log('Note Add Error ', err);
    });
}  
2 Answers

Same problem hier. Tried it with allow read, write: if true; and allow read, write;. It doesn't matter if I'm authenticated or not. My errorcode is: permission-denied, my errormessage is Missing or insufficient permissions.

Now I am able to create the documents. Issue was happening because my service method was still using FireBase RealTime Database code to insert the data, my bad(I was using Firebase RT before, simply wanted to try out FireStore). Regarding issue from console, I am still facing issue when I try Google Chrome (ver- 60.0.3112.90). But its working when I try from FireFox. Thanks all for your responses.

Related