Firestore won't let me one more map to they array

I'm in desperate need of help handling Firestore rules. I have these rules to handle the collection on the picture I provided:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /items/{itemId} {
allow read;
allow create, update: if request.auth != null
&& request.resource.data.reviews.size() == 1
&& 'reviews' in request.resource.data
&& request.resource.data.reviews[0].keys().hasAll(['userId', 'rating', 'review', 'userName'])
&& request.resource.data.reviews[0].size() == 4
&& request.resource.data.reviews[0].userId == request.auth.uid
&& !(exists(/databases/$(database)/documents/items/$(itemId)/reviews/$(request.resource.data.reviews[0].userId)))
}
}
}
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /items/{itemId} {
allow read;
allow create, update: if request.auth != null
&& request.resource.data.reviews.size() == 1
&& 'reviews' in request.resource.data
&& request.resource.data.reviews[0].keys().hasAll(['userId', 'rating', 'review', 'userName'])
&& request.resource.data.reviews[0].size() == 4
&& request.resource.data.reviews[0].userId == request.auth.uid
&& !(exists(/databases/$(database)/documents/items/$(itemId)/reviews/$(request.resource.data.reviews[0].userId)))
}
}
}
For some odd reason, this ruleset would only let me add one review (along with creating the array itself). Here's the request itself:
const handleSubmit = async () => {
const itemRef = doc(db, "items", itemId);
await updateDoc(itemRef, {
reviews: arrayUnion({
userId,
rating,
review,
userName,
}),
});
};
const handleSubmit = async () => {
const itemRef = doc(db, "items", itemId);
await updateDoc(itemRef, {
reviews: arrayUnion({
userId,
rating,
review,
userName,
}),
});
};
Why on Earth wouldn't it let me add one more map to my "reviews" array? It just pisses me off with "insufficient permissions" on my client side and I have no idea what's wrong. I've been fighting this for couple of days and I think I'm loosing my mind.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server