Reputation: 913
I am not able to read/write data to firestore with rules in place.
I can access my data and do operations on it with no rules set as shown below:
match /{document=**} {
allow read, write: if true;
}
But I am getting the "permission denied" error with following rules.
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
Here is my dart code:
if (uid == null) {
user = await a.currentUser();
uid = user.uid;
}
DocumentReference docRef = firestore.collection('users').document(uid);
CollectionReference locations = docRef.collection('locations');
await locations.document().setData(<String, double>{
'latitude': latitude,
'longitude': longitude,
});
I can think of two scenarios in which this request fails:
Please help me debug this issue.
Edit 1:
User u = await a.onAuthStateChanged.first;
if (u != null) {....}
Is there anyway I can print the actual request being sent to the firebase from dart using cloud_firestore package?
Edit 2
Any help on why this might be happening?
Upvotes: 1
Views: 6162
Reputation: 7150
Just change your rules to as below if you want to allow anybody to upload the documents.
allow read, write;
If you want to allow only authenticated users to allow upload the files or documents to your firebase change your rules to
allow read, write: if request.auth != null;
Upvotes: 3