Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firestore database validation on type

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);
like image 236
ralphinator80 Avatar asked Jun 22 '18 23:06

ralphinator80


People also ask

Can I use firestore without authentication?

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.

How do you make a field unique in Firebase?

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.

What is reference data type in Firebase?

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 .

How to set rules for Firestore database?

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.


1 Answers

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;
like image 77
ralphinator80 Avatar answered Oct 24 '22 11:10

ralphinator80