Reputation: 724
I have this problem and try to fix with all solutions I had found,but still not works. My rules in firebase cloud firestore is :
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write : if auth != null ;
}
}
}
And I had already enable Sign-in Method Anonymously.
android/build.gradle
:
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.1'
android/app/build.gradle
:
compile project(':react-native-firebase')
compile project(':react-native-fbsdk')
implementation project(':react-native-firebase')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation 'com.google.firebase:firebase-firestore:17.1.0'
Testing.js
:
firebase.auth().signInAnonymously().then(()=>{
firebase.app().firestore().collection('Hello').doc('hello').set({
id:'fadsa'
}).catch((err)=>{
alert(err);
})
})
Upvotes: 68
Views: 107549
Reputation: 9425
I forgot to put a semicolon at the end:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null //--> put the semicolon
}
}
}
changing to:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
Upvotes: 0
Reputation: 14938
from that:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
change to this:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
Upvotes: 84
Reputation: 325
For those encountering issues with the Firebase emulator, it's important to note that in the root folder where the emulator stores its data, there is a file named firestore.rules
. Update the rules there just as you would for Firestore in the cloud.
Upvotes: 1
Reputation: 11
You can into FirestoreDatabase, then update timestamp. Let the timestamp longer, then click on Develop and test.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// This rule allows anyone with your Firestore database reference 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
// all client requests to your Firestore database will be denied until you Update
// your rules
match /{document=**} {
allow read, write: if request.time < timestamp.date(2025, 8, 9);
}
}
}
Upvotes: 0
Reputation: 19
This error was also occurring for me because I was testing my app using an internal test track and I need to enable a 'test API response' for App Check in the Google Play console. I also added my SHA256 fingerprint of my app from Google Play console into the Firebase console.
Upvotes: -1
Reputation: 1
I had the same error, I struggled a lot because I missed "No App Check token for request." warning.
If you enforced Cloud Firestore on app check, must configure, unenforce or add token. [firebase appcheck]
Upvotes: -1
Reputation: 613
Just to point out, this can also happen if you have a function that runs (can be periodic) it ran after you are signed out.
Upvotes: 1
Reputation: 847
Just want to add that this error can also happen if you enabled "App check" in Firebase and enforced the checking of the App check token but the token is missing in the requests.
In that case, you need to add the plugin firebase_app_check.
Upvotes: 7
Reputation: 555
If you don't use authentication inside your app and only used the Firebase Firestore. So you can change it simply like this.
Change This
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
Into This
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
And last don't forget to publish these changes in order to save it.
If you have specified through timeStamp
If you have specified your Firestore rules through timeStamp then simply increase the length of duration of time.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2023, 3, 14);;
}
}
}
Note: It is just for practicing and playing with Firestore data. If you want to build a production-level app then be sure to securely define your Firestore rules.
Upvotes: 15
Reputation: 69
I had the same error with my flutter application on Android Stuido and when I check the rules I saw there was a time limitation for allowing read and write operations. So I just extended the time period as below:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2022, 9, 29);
}
}
}
Upvotes: 5
Reputation: 17
Update your rules file on Firestore console. Set permission to read and write to true.
Upvotes: -5
Reputation: 390
This is an issue because of the rules that your DB currently has. Please check both datebases, Realtime and Firestore.
As in general, having full security rules or any other rule that is not complitely understood by RD or CF logic will get you that error everytime.
> // Full security
>
> { "rules": {
> ".read": false,
> ".write": false } }
in Firestore you can configurate that as the following:
> service cloud.firestore { match /databases/{database}/documents {
> match /{document=**} {
> allow read: if auth != null;
> allow write: if auth != null;
> } } }
For more examples you can see: https://gist.github.com/codediodeio/6dbce1305b9556c2136492522e2100f6 https://firebase.google.com/docs/database/security
Upvotes: 25