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}
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.