Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cloud Firestore use regex in security rule

I’m trying to give read rights only to members of one specific domain. I figured out that using regex would be the best way so i tried to use this syntax:

allow read: if request.auth.token.firebase.sign_in_provider == "google.com" && 
               request.auth.token.email.matches(/^.+@gbl\.cz$/);

But I’m getting following errors:

Error saving rules – Line 5: Forward slash ‘/’ found where identifier or binding expected.; Line 5: Missing ‘match’ keyword before path.; Line 5: mismatched input ‘.’ expecting {‘{‘, ‘/’, PATH_SEGMENT}; Line 5: Unexpected ‘+’.; Line 5: token recognition error at: ”; Line 5: Forward slash ‘/’ found where identifier or binding expected.; Line 5: Missing ‘match’ keyword before path.; Line 5: mismatched input ‘)’ expecting {‘{‘, ‘/’, PATH_SEGMENT}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Even when pattern in matches is striped down to /.+/ it throws

Error saving rules – Line 5: Forward slash ‘/’ found where identifier or binding expected.

Any idea how to solve this? I already went through documentation, but didn’t find anything useful…

>Solution :

From a quick glance at the reference documentation for String.matches in Firebase’s security rules, it seems to only accept a string parameter. So you might want to pass in your regex as a string, instead of a literal.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading