quickstart-js: Permission denied in Firebase Realtime Database Quickstart project

I’ve cloned this repo and followed exactly those steps listed here: https://github.com/firebase/quickstart-js/blob/master/database/README.md#getting-started

Unfortunately, after opening localhost:5000 and logging in using exsiting Google account, I firstly get a warning:

@firebase/database: FIREBASE WARNING: set at /users/[some_long_key] failed: permission_denied

Then error:

Uncaught (in promise) Error: PERMISSION_DENIED: Permission denied at index.esm.js:13070 at yt (index.esm.js:684) at t.callOnCompleteCallback (index.esm.js:13061) at index.esm.js:12838 at index.esm.js:12013 at n.onDataMessage_ (index.esm.js:12046) at t.onDataMessage_ (index.esm.js:11331) at t.onPrimaryMessageReceived_ (index.esm.js:11325) at t.onMessage (index.esm.js:11226) at t.appendFrame_ (index.esm.js:10831)

Which points me to some file (index.esm.js) which doesn’t really helps with figuring out what could be wrong.

How can I debug why Firebase returned PERMISSION_DENIED error? What could go wrong?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 29 (1 by maintainers)

Most upvoted comments

@piotrek-k found the solution.

  1. Go to the “Database” option you mentioned.
  2. There on the Blue Header you’ll find a dropdown which says Cloud Firestore Beta
  3. Change it to “Realtime database”
  4. Go to Rules and set .write .read both to true

Let me know how it goes.

Go to Firebase console -> Real time database -> permissions -> Then allow non authenticated users.

Change this: screen shot 2019-02-21 at 09 55 43

To: screen shot 2019-02-21 at 09 56 40

And you’re going to figure out that you were editing on the wrong service… just like I did! 🤕

Go to database, next to title there are 2 options: Cloud Firestore, Realtime database Select Realtime database and go to rules

change rules to true.

  1. Open firebase, select database on the left hand side.
  2. Now on the right hand side, select [Realtime database] from the dropdown and change the rules to: { “rules”: { “.read”: true, “.write”: true } }

it workss…!!

I have the same issue, but my rules look like they are already wide open. Any other ideas? image

Here is the error message: image

And the code that triggers it: image

I have verified that the Collection “twittusers” exists in the database.

@nicoabie: yes, I figured it out earlier and the problem was indeed that I mistook Realtime database with cloud Firestore. Thanks!

I have the same problem too ^^. All the solutions I’ve found are the same. i.e. change your rules to: { "rules": { ".read": true, ".write": true } }

@AJ-Creations, there is not such option like “Real time database” in firebase console in menu on the left. There is only “Database” option, but am I supposed to create database then? Why isn’t it mentioned in “readme” file?

Also, why would I “allow non authenticated users”, if I firstly log in (so I’m authenticated user) and then (after authenitcation) the error appears?

https://stackoverflow.com/questions/51707898/permission-denied-when-permissions-are-actually-allowed

The solution here fixed this problem for me. Hope it works for you too.

Go inside your realtime database and set this rules like this

“rules”: { “.read”: true, “.write”: true }

index.cjs.js:12919 Uncaught (in promise) Error: PERMISSION_DENIED: Permission denied at index.cjs.js:12919 at exceptionGuard (index.cjs.js:700) at Repo…/node_modules/@firebase/database/dist/index.cjs.js.Repo.callOnCompleteCallback (index.cjs.js:12909) at index.cjs.js:12725 at index.cjs.js:11945 at PersistentConnection…/node_modules/@firebase/database/dist/index.cjs.js.PersistentConnection.onDataMessage_ (index.cjs.js:11975) at Connection…/node_modules/@firebase/database/dist/index.cjs.js.Connection.onDataMessage_ (index.cjs.js:11289) at Connection…/node_modules/@firebase/database/dist/index.cjs.js.Connection.onPrimaryMessageReceived_ (index.cjs.js:11283) at WebSocketConnection.onMessage (index.cjs.js:11184) at WebSocketConnection…/node_modules/@firebase/database/dist/index.cjs.js.WebSocketConnection.appendFrame_ (index.cjs.js:10772)

for this error

{ “rules”: { “.read”: “true”, “.write”: “true” } }

can’t be a solution

You should never set the “read” and “write” access on your database root to “true”, and seeing so many suggesting that is scary!

I’ve been having “PERMISSION DENIED” issues with my Firebase REALTIME Database (my access rights for read and write are tied to $uid, so there is no unauthenticated access to my data). I am using FirebaseAuth.signInWithEmailAndPassword, and in my case I could access my data right after logging in, but as soon as I refreshed my app, the database refused to return anything other than the ‘PERMISSION DENIED’ error.

It turns out that listening to the AngularFireAuth.authState Observable changes is necessary to somehow keep the user session alive, and as soon as I added that to my AuthGuard class, the error was gone and I had access to my data without any issues - even after refreshing the page.

The documentation still shows the old firebase.auth().onAuthStateChanged(function(user)... way of listening to state changes.

Here is the code snippet from my AuthGuard file:

return this.afAuth.authState.pipe(
  take(1), 
  map(user => {
    const isAuthenticated = !!user;

    if (isAuthenticated) {
      return true;
    }

    return this.router.createUrlTree(['/auth']);
  })
);

I hope this helps.

@cleophasmogeni thanks for sharing your confusion about the two different databases.

Just to be clear for everyone, you should NEVER set these rules in production:

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

That means anyone in the world can read and write all of your data. If your credit card is connected, that means anyone in the world can cost you money. It’s fine if you want to use those rules for testing a quickstart, but be sure to change them to something else eventually.

You save my day. @nicoabie

help for cloud firestore

https://firebase.google.com/docs/firestore/quickstart

var db = firebase.firestore();
db.collection("users").add({
    first: "Ada",
    last: "Lovelace",
    born: 1815
})
.then(function(docRef) {
    console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
    console.error("Error adding document: ", error);
});

I have a Realtime database that works perfect with default “test db no protection settings”

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

And a Cloud Firestore for wich default “test db no protection settings” is completly different

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

Diffrerent rules for different architectures

I found the strings from rule simulator “/label1/label2” (I tryed all the posible strings - this is crazy)

Conculsion Cloud Firestore looks more like Couch DB than Firebase. It is a different approach and nobody is telling us that. Probably it is similar with other databases that Google developed and where here in the Cloud Console but we did not use Switch to RealTime Database or learn a new database (is not about rules here - is a different architecture and different calls from java if you want to write something - it is about writing JSON documents not about writing values on trees like in Firebase) … if you do not have calls like this in your code

    DocumentReference docRef = db.collection("users").document("alovelace");

then you are a RealTime user - go back If you want to learn the new Firestore Cloud start with this example https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/firestore

i have same problem