quickstart-js icon indicating copy to clipboard operation
quickstart-js copied to clipboard

Permission denied in Firebase Realtime Database Quickstart project

Open piotrek-k opened this issue 8 years ago • 30 comments

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?

piotrek-k avatar Jul 31 '18 16:07 piotrek-k

The database permissions must be corrected.

oscl avatar Jul 31 '18 16:07 oscl

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

oscl avatar Jul 31 '18 16:07 oscl

@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?

piotrek-k avatar Aug 01 '18 16:08 piotrek-k

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

nicoabie avatar Sep 01 '18 14:09 nicoabie

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

piotrek-k avatar Sep 01 '18 14:09 piotrek-k

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

anindya9477 avatar Sep 16 '18 15:09 anindya9477

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.

poweruptechacademy avatar Oct 11 '18 03:10 poweruptechacademy

i have same problem

fer3as avatar Oct 20 '18 14:10 fer3as

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 } }

cloeg97 avatar Oct 24 '18 17:10 cloeg97

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.

cloeg97 avatar Oct 24 '18 17:10 cloeg97

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.

jaywant3 avatar Nov 17 '18 22:11 jaywant3

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

dorinionescu avatar Dec 07 '18 00:12 dorinionescu

Go inside your realtime database and set this rules like this

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

joker7blue avatar Jan 14 '19 13:01 joker7blue

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);
});

ddaydd avatar Jan 19 '19 14:01 ddaydd

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! 🤕

renatogalvones avatar Feb 21 '19 12:02 renatogalvones

Thank you @renatogalvones

jlgomes avatar Mar 04 '19 23:03 jlgomes

You save my day. @nicoabie

kuesugi avatar Mar 26 '19 02:03 kuesugi

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

thanks much appreciated

zafar94 avatar May 18 '19 17:05 zafar94

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

Very Helpful. Thank you

harravi1 avatar Jun 05 '19 05:06 harravi1

What confuses a novice here is navigating to the right place. There is cloud firestore and Real time database in your Firebase console. In this case, several people have already provided a solution already. Make sure you navigate to Firebase console > Real time database > permissions and set the rules.

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

Hope this is straightforward now for anyone facing the issue.

cleophasmogeni avatar Jun 09 '19 13:06 cleophasmogeni