Permission_denied to access firebase datastore

2019-03-06 16:02发布

问题:

I am trying to get access to my firebase data to run a little test. I have setup an app in the firebase console and set the access rules to:

// Allow read/write access to all users under any conditions 
// Warning: **NEVER** use this rule set in production; it allows
// anyone to overwrite your entire database.
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

Nevertheless I am always getting the following error:

angular.js:14328 Error: permission_denied at /messages: Client doesn't have permission to access the desired data.

at this line of code:

var ref = firebase.database().ref().child('messages');

What I am I missing?

回答1:

Those rules are for firestore and not firebase-realtime database.

In the console go to the database section and click on the dropdown then choose RealTime database:

For the realtime database change your rules to this:

 {
 "rules": {
   ".read": true,
   ".write": true
  }
}

and then perform the tests.