Firebase Security Rules Regex in Path

眉间皱痕 提交于 2021-02-05 09:27:08

问题


I have security rule write like this :

 /databases/{database}/documents {

     match /collection_COUNTRY_EN/{docId} {
          allow....
     }

     match /collection_COUNTRY_ES/{docId} {
          allow... 
     }
}

Where the rule are identical to all the country. Is there a way to implement regex in the match /path to have the same rule for all the collection that start with something and end with a country code ? Or does i have to structure my data in a different way ?

Thanks for your time.


回答1:


Security rules do not support regex in the path match. You can only wildcard on the full name of a path segment.

What you might want to do instead is organize all your common top-level collection into subcollections organized under a known document, and apply the same rules to each of them that way:

match /countries/data/{countryCollection}/{docId} {
    allow...
}

This would apply the same permissions to all country subcollections organized under /countries/data, which can be an empty document, or even a non-existent document.



来源:https://stackoverflow.com/questions/61237642/firebase-security-rules-regex-in-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!