Firebase 如果文档中的属性位于令牌附加声明[Firestore]中的字符串列表中,则允许读取
我试图在Firestore中设置规则,仅当文档中的属性包含在字符串列表中时,才允许用户访问文档。字符串列表包含在python后端生成的Firebase令牌的附加声明中Firebase 如果文档中的属性位于令牌附加声明[Firestore]中的字符串列表中,则允许读取,firebase,google-cloud-firestore,Firebase,Google Cloud Firestore,我试图在Firestore中设置规则,仅当文档中的属性包含在字符串列表中时,才允许用户访问文档。字符串列表包含在python后端生成的Firebase令牌的附加声明中 service cloud.firestore { match /databases/{database}/documents { match /myList/{itemId} { allow read: if resource.data.location_id in request.auth.toke
service cloud.firestore {
match /databases/{database}/documents {
match /myList/{itemId} {
allow read: if resource.data.location_id in request.auth.token.locations
}
}
}
但是,执行查询仍然会返回所有文档,而不是仅返回位置_id位于我们在附加声明中列出的列表中的文档。我不确定这是否与Firestore规则有关,或者我的Firestore规则中是否存在语法错误
我的firestore结构看起来像myList/{itemId}/(这里的项目属性,包括location\u id属性,它看起来像location\u id:“7”)
以下是我尝试实现此规则的参考
而且根据文件,
在CloudFireStore中有两个读取和查询操作:get
和列表。它们对应于get()和where().get()(查询),
客户端库中的方法。为方便起见,请阅读
操作允许这两种情况
因此,指定read应该涵盖这两种情况。我还曾经解码我的firebase令牌,以确保正确添加声明,并且它确实显示在我的令牌中
"claims": {
"locations": [
"6"
]
},
编辑:
我已经尝试过像下面这样努力编码一个值,但我甚至无法让它工作,它仍然返回所有文档
service cloud.firestore {
match /databases/{database}/documents {
match /myList/{itemId} {
allow read: if resource.data.location_id == '6'
}
}
}
简单的回答是,['foo','bar']中的
会导致条件的隐式或
,这是当前不支持的查询约束
目前,您必须编写一个规则,使这或明确:
// works fine for single gets
allow get: if resource.data.itemId in ['foo', 'bar']
// need to expand this for queries
allow list: if resource.data.itemId == 'foo' || resource.data.itemId == 'bar'
简单的回答是,['foo','bar']
中的会导致条件的隐式或
,这是当前不支持的查询约束
目前,您必须编写一个规则,使这或明确:
// works fine for single gets
allow get: if resource.data.itemId in ['foo', 'bar']
// need to expand this for queries
allow list: if resource.data.itemId == 'foo' || resource.data.itemId == 'bar'
所以service cloud.firestore{match/databases/{database}/documents{match/myList/{itemId}{allow-get:if-resource.data.itemId在['7']允许列表中:if-resource.data.itemId='7'}
?如果你只有一个项目,你不需要在['7']中执行
您只需使用==“7”
。请注意,您需要确保您想要'7'
(字符串)vs7
(数字)。因此service cloud.firestore{match/databases/{database}/documents{match/myList/{itemId}{allow get:if resource.data.itemId in['7']允许列表:if resource.data.itemId='7'.\resource.data.itemId='7'}}
?如果您只有一个项目,您不需要在['7']
中执行,只需使用=='7'
。请注意,您需要确保您想要的是'7'
(字符串)与7
(数字)。