I'm trying to create a rule in Firestore that restricts usage to all CRUD operations for users that belongs to a specific domain, My issue is that seems like contains clause doesn't exist in the rule context.
this is my rule:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if isUserAndSignedIn();
}
}
function isUserAndSignedIn(){
return request.auth != null && request.auth.token.email.contains('domain.com')
}
}
the error I'm getting is: Error: simulator.rules line [9], column [36]. Function not found error: Name: [contains].
I also tried with indexOf like
request.auth.token.email.indexOf('domain.com')!=-1 request.auth.token.email.endsWith('domain.com')
request.auth.token.email
is going to be a String, and according to the reference docs, String doesn't have a method called "contains". It does have a method calledmatches
for using regular expressions, and you can see the documentation has a handy bit of sample code:Which you should be able to adapt to your case: