After running the query shown below, I encountered a permission-denied
message with an error in the "Monitor rules" tab.
const timeNow = useMemo(() => Timestamp.now(), []);
const query = query(
postRef,
where("tags", "array-contains-any", ["Event"]),
where("publishDate", "<=", timeNow),
orderBy("publishDate", "desc"),
limit(4)
);
Upon further investigation, I identified that the issue stemmed from the security rules section:
service cloud.firestore {
match /databases/{database}/documents {
match /posts/{postID}{
allow read: if resource.data.publishDate <= request.time;
}
}
}
I experimented by adjusting the rule to
resource.data.publishDate != null
, which returned true and allowed the request. However, altering it to resource.data.publishDate is timestamp
resulted in a denial.
This leaves me questioning whether there's an error in the query itself or if I overlooked something within the security rules?