Anyone know how to validate base on instanceof
?
This seems like a no brainer check but I cannot find reference for this type of validation in the docs and my attempts have not been correct.
I want to fail if the value is not a Date
. It might be a Timestamp
in the current version of firestore.
Failed attempts
allow write: if request.resource.data.date instanceof Date;
allow write: if request.resource.data.date instanceof Timestamp;
allow write: if !!Timestamp(request.resource.data.date);
allow write: if !!rules.Timestamp(request.resource.data.date);
allow write: if !!rules.Timestamp.date(request.data.date);
allow write: if !!Timestamp.date(request.data.date);
allow write: if !!Timestamp(request.data.date);
To be honest, without Firebase Authentication, it's not possible to accept writes to a database without Authentication and also avoid abuse, since anyone could write anything from anywhere on the internet. This could also cost you large amounts of money if someone discovers your "open" database.
If you need some value (or combination of values) to be unique, you need to create a node that contains that value (or combination) as its key. If you need to guarantee that multiple values (or combinations) are unique, you'll need multiple of such nodes.
CLOUD FIRESTORE. REFERENCE DATA TYPE IS ONE OF THE MANY DATA TYPES OF CLOUD FIRESTORE . THIS DATA TYPE ACTS LIKE FOREIGNKEY EVEN THOUGH IT IS NOT ACTUALLY A FOREIGNKEY . THE MAIN ADVANTAGE OF USING IT IS TO REFER A CERTAIN DOCUMENT TO ANOTHER DOCUMENT .
To set up and deploy your first set of rules, open the Rules tab in the Cloud Firestore section of the Firebase console. Write your rules in the online editor, then click Publish.
I was clued into the solution through firebase support. The key comparator is the is
keyword.
allow write: if request.resource.data.date is timestamp;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With