Restric firestore CRUD to users within a specific domain

后端 未结 1 1043

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 claus

1条回答
  •  春和景丽
    2021-01-16 12:16

    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 called matches for using regular expressions, and you can see the documentation has a handy bit of sample code:

    'user@domain.com'.matches('.*@domain[.]com') == true
    

    Which you should be able to adapt to your case:

    return request.auth != null && request.auth.token.email.matches('.*@domain[.]com')
    

    0 讨论(0)
提交回复
热议问题