Bad idea: I am going to allow anonymous website users to log a visit to a Firestore collection, but I don't want them stomping around and using my site to serve bad things™️, how do I constrain the writes?
(admittedly poor practice, this is just a prototype, the right way to do this would be to hit up a middle layer, have the middle layer validate the write request, only allow the firestore DB to be written to from the middle layer, etc.)
I'd like to constrain the documents that the visitor can add to the collection to a simple "add a doc with a number and timestamp."
Something like
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if
request.time < timestamp.date(2021, 5, 22);
}
match /{pageId}/visit/} {
allow write: if
request.time < timestamp.date(2021, 5, 22)
&& request.num EXISTS AS A NUMBER
&& request.timestamp EXISTS AS A TIMESTAMP
&& NO OTHER FUNNY STUFF ALLOWED;
}
}
}