This question already has answers here:
Firebase chat app setValue failed error with a public database?
(2 answers)
Closed 3 years ago.
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?
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.
Related
I have a flutter app in development and I use firestore as the storage.
users (collections)-> userId(doc) -> records (collection)
I am using this query:
FirebaseFirestore.instance.collection('users').doc(_userId).collection('records')
I notice when I test my app on simulator and test on my physical iphone, the list of documents I get from firestore are different. And on both env, I notice there are some documents are missing when I fetch from firestore. I can see the documents are in the firestore, but when I check the result of the query, I couldn't get the full list of documents in the collection. I notice I can only get the newly added documents. But the older documents, I couldn't get them anymore.
Anyone know where to start to debug this issue? Thanks.
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
I checked the query exception, no exception detected, the query succeeded.
Found out that the way I read from firebase has some problems.
I was using this to read from the subcollection:
FirebaseFirestore.instance.collection('users').doc(_userId).collection('records').snapshots()
which returns a stream and I didn't listen to it properly.
Changed to
FirebaseFirestore.instance.collection('users').doc(_userId).collection('records').get()
which returns a future, and using await to wait this future. Now it works.
I'm quite new to Firebase, but either I misunderstand something completely or there's something wrong with my Firebase account.
I added a Firestore Database to my Firebase app, and initially I chose it to be created in test mode. As far as I've read in the docs, test mode differs from production mode only by the default security rules.
I wanted to configure my rules properly, so the users can only access their own data.
However, I couldn't make it work, so I tried to configure my Firestore security rules to not allow any read or write operations to anyone. This is what I have currently set in Firestore Database -> Rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
As I understand, these rules should not allow any read or writes in any collection in my database.
The rules playground tells me exactly that when I try to run any request:
However, from my NextJS app I'm still able to get the data as follows:
import {
getFirebaseAdmin
} from 'next-firebase-auth';
// ...
const categoriesDocument = await getFirebaseAdmin()
.firestore()
.collection('categories')
.doc('D47pV7TxNpDNYNkHgfU0')
.get();
and it all works just fine. I'm also sure the data is fetched from exactly this Firestore db, because when I alter some documents it's reflected in the data fetched.
I also noticed that in Firebase in Firestore Database -> Rules -> Monitor rules I see no results at all (total allows: 0, total denies: 0, total errors: 0).
Any idea what could be wrong here? What am I missing?
On the server, you're using firestore as admin. Rules don't apply there.
I am new to firebase and i have an error in console that i really don't know its source:
redux-firestore listener error: FirebaseError: Missing or insufficient permissions.
I don't know is this sufficient to explain my problem, but because i am new to firebase and firestore i can't explain more or bring some piece of code, everything was working fine but suddenly i got this error, what can be the source of that error?? how to fix it??
One reason you can suddenly be denied access to your Firebase database without having changed anything is that database access rules can have expiry dates, and the default Open Access rules do. E.g., if you examine your database rules at https://console.firebase.google.com/, you may see a line similar to this:
match /{document=**} {
allow read, write: if request.time < timestamp.date(2020, 7, 4);
}
Try changing the date into the future (and click Publish), and see if that helps.
Note: You should set up proper rules that do not expire ASAP (unless expiry is part of your design). See Avoid insecure rules for more details.
This question already has answers here:
Email: [Firebase] Client access to your Cloud Firestore database expiring in X day(s)
(6 answers)
Closed 3 years ago.
Reached mail what needs to be made?
rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// This rule allows anyone on the internet to view, edit, and delete
// all data in your Firestore database. It is useful for getting
// started, but it is configured to expire after 30 days because it
// leaves your app open to attackers. At that time, all client
// requests to your Firestore database will be denied.
//
// Make sure to write security rules for your app before that time, or else
// your app will lose access to your Firestore database
match /{document=**} {
allow read, write: if request.time < timestamp.date(2020, 2, 15);
}
}
}
Is it worth the worry? Will this break the application if nothing is done?
Your security rules are set to reject all access to your database on the date specified in the rules:
timestamp.date(2020, 2, 15)
Which is February 15, 2020. This will probably make your app stop working.
You can bump the date back if you want, but you should definitely implement proper rules so that your database isn't readable and writable by anyone with an internet connection.
Faced this error while working on a new React-Native project and using React-Native-Firebase library. Followed all tutorial setup steps and got this error. It's likely that this error can be faced in not react-native projects as well.
I've spent so many hours trying to fix it and didn't find a solution to my problem on stackoverflow.
Turns out, the solution was as simple as going to Firebase Console => Storage => click Getting started which creates default Storage rules.
It was a new project and no storage rules existed.
Solution was found by running
adb logcat command, output showed something like
check security rules for firebase storage and
no permission for storage
Hope this will save you hours debugging I wasted!
In my case the problem was that I had a wrong storage bucket URL set up (something.firebaseapp.com) when it should have been something.appspot.com
Just make the rules of your firebase storage to be true i.e. allow read and write to be true. That will do the trick. Like this
rules version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}