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?
The database permissions must be corrected.
Go to Firebase console -> Real time database -> permissions -> Then allow non authenticated users.
@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 found the solution.
- Go to the "Database" option you mentioned.
- There on the Blue Header you'll find a dropdown which says Cloud Firestore Beta
- Change it to "Realtime database"
- Go to Rules and set .write .read both to true
Let me know how it goes.
@nicoabie: yes, I figured it out earlier and the problem was indeed that I mistook Realtime database with cloud Firestore. Thanks!
- Open firebase, select database on the left hand side.
- 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?

Here is the error message:

And the code that triggers it:

I have verified that the Collection "twittusers" exists in the database.
i have same problem
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
}
}
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 to database, next to title there are 2 options: Cloud Firestore, Realtime database Select Realtime database and go to rules
change rules to true.
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
Go inside your realtime database and set this rules like this
"rules": { ".read": true, ".write": true }
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);
});
Change this:

To:

And you're going to figure out that you were editing on the wrong service... just like I did! 🤕
Thank you @renatogalvones
You save my day. @nicoabie
@piotrek-k found the solution.
- Go to the "Database" option you mentioned.
- There on the Blue Header you'll find a dropdown which says Cloud Firestore Beta
- Change it to "Realtime database"
- Go to Rules and set .write .read both to true
Let me know how it goes.
thanks much appreciated
Go to Firebase console -> Real time database -> permissions -> Then allow non authenticated users.
Very Helpful. Thank you
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.