0

Basically, i am trying to read data from a firebase real time database. I receive permissions denied.

Firebase Console -> database -> Rules :

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

My application code:

const db = firebase.database(firebase.initializeApp(
      {databaseURL: “myApp.firebaseio.com"}
))
db.ref("/budgets/currentBudget")
  .once("value")
  .then((snapshot)=>console.log(snapshot))

I would expect to connect to the database and be able to read the data because of the rules i have set. I receive this error:

Error:

 index.cjs.js:738 Uncaught (in promise) Error: permission_denied at /budgets/currentBudget: Client doesn't have permission to access the desired data.
    at errorForServerCode (index.cjs.js:738)
    at onComplete (index.cjs.js:10124)
    at Object.onComplete (index.cjs.js:14314)
    at index.cjs.js:13289
    at PersistentConnection.onDataMessage_ (index.cjs.js:13594)
    at Connection.onDataMessage_ (index.cjs.js:12735)
    at Connection.onPrimaryMessageReceived_ (index.cjs.js:12728)
    at WebSocketConnection.onMessage (index.cjs.js:12607)
    at WebSocketConnection.appendFrame_ (index.cjs.js:12144)
    at WebSocketConnection.handleIncomingFrame (index.cjs.js:12203)
    at WebSocket.mySock.onmessage (index.cjs.js:12078)

There are a few questions asking about this but most of them are solved when the rules are simply changed to true on both read and write. Any ideas how to get this working?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Abram
  • 59
  • 1
  • 12
  • The security rules you're showing apply to Cloud Firestore, while the code you're showing is accessing the Realtime Database. While both databases are part of Firebase, they're completely separate, and the security rules for one don't apply to the other. To fix the error, you will have to set the rules for the Realtime Database. For a walkthrough of how to do that, see https://stackoverflow.com/a/52129163 – Frank van Puffelen Oct 06 '19 at 20:35

1 Answers1

1

The rules you're showing are not for Firebase Realtime Database. Those are for Cloud Firestore, which is a completely different database. Realtime Database has a different rules language, which are entered into a different part of the Firebase console. Start learning about Realime Database rules here.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441