[英]Listen for query at chats/*************/messages failed: Missing or insufficient permissions
I wrote a firebase rule to allow read only if uid
is in user array of parent collection.我写了一个 firebase 规则来允许只读如果
uid
在父集合的用户数组中。
When I try to query collection to get list of document, I get the error当我尝试查询集合以获取文档列表时,出现错误
> Listen for query at chats/**************/messages failed:
> Missing or insufficient permissions.
Here is security rule I user for collection:这是我收集用户的安全规则:
match /chat/{chat_id}/messages/{id} {
allow read, write: if request.auth != null && request.auth.uid in get(/databases/$(database)/documents/chat/$(chat_id)).data.users;
allow delete, update: if false;
}
Is it that my security rule is wrong or a query cannot be performed on collection with such rule?.是我的安全规则错误还是无法对具有此类规则的集合执行查询?。
Posting this as a community wiki:将此作为社区 Wiki 发布:
Firestore Security Rules should be matched by the correct collection name as @Anga mentioned by correcting the collection name should solve the issue. Firestore 安全规则应与正确的集合名称匹配,正如@Anga 提到的通过更正集合名称应该可以解决问题。
I presume that users
is an array of uid's (strings) like:我假设
users
是一组 uid(字符串),例如:
users = ["uid1", "uid2", "uid3"]
You could also try storing the users as a dictionary:您还可以尝试将用户存储为字典:
users = {uid1: ..., uid2: ... , uid3: ...}
And access it the following way:并通过以下方式访问它:
allow read, write: if request.auth != null && get(/databases/$(database)/documents/chat/$(chat_id)).data.users[reqeust.auth.uid] != null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.