动态Firestore规则?
我有2个集合,我控制访问权限,但授予customClaim。现在,如果我有越来越多的集合规则将变得很长。
例
service cloud.firestore { match /databases/{database}/documents { match /india/{documentID} { allow read, write : if request.auth.token.india_admin == true allow read : if true } } match /databases/{database}/documents { match /japan/{documentID} { allow read, write : if request.auth.token.japan_admin == true allow read : if true } } }
有没有办法可以通过使用集合名称变量来概括它
您现在正在做的事情允许无条件地读取所有内容。这就是allow read: if true
所做的。
试试这个,使用通配符作为集合名称:
match /{country}/{documentID} {
allow read, write : if request.auth.token[country + "_admin"] == true;
}
请注意,这具有应用于所有顶级集合的副作用,即使是那些不代表国家/地区的集合。如果您使用其他需要不同规则的顶级集合,则可能需要将所有特定于国家/地区的集合推送到单个顶级集合下的子集合中。