【发布时间】:2022-02-20 21:17:14
【问题描述】:
我想只授予成员组中存在的用户读写权限,但我不知道为什么它不起作用?
这是firestore中的规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /Users/{uid} {
allow write: if request.auth != null && request.auth.uid == uid;
allow read : if request.auth != null;
}
match /GroupChat/{document=**} {
allow read,create,update: if request.auth != null && request.auth.uid in request.resource.data.Members;
}
}
}
查询:
FirebaseFirestore.instance
.collection("GroupChat")
.where("Members",
arrayContains: FirebaseAuth.instance.currentUser!.uid)
.snapshots(),
当我想在我的APP中显示信息时,我得到了这个错误:
W/Firestore(14600): (24.0.0) [Firestore]: Listen for Query(target=Query(GroupChat where Members array_contains 0FQhApDgWMVNTpOiDewF3qJX7IA3 order by name);limitType=LIMIT_TO_FIRST) 失败:状态{code=PERMISSION_DENIED, description=缺少权限或权限不足。, cause=null}
【问题讨论】:
-
你在真机上运行过应用吗?
-
不,我还没有
-
错误描述=断开空闲流可能是模拟器的原因,请在真机中检查然后回复。
-
我认为我在使用 xcode 运行 Iphone 时遇到问题,所以我只是重新启动 IDLE,现在它给了我这个错误:W/Firestore(14600): (24.0.0) [Firestore]:侦听 Query(target=Query(GroupChat where Members array_contains 0FQhApDgWMVNTpOiDewF3qJX7IA3 order by name);limitType=LIMIT_TO_FIRST) 失败:Status{code=PERMISSION_DENIED, description=Missing or enough permissions., cause=null} I在我的问题正文中更改了谢谢@Debjeet
-
您可以尝试将规则更改为
request.auth.uid in resource.data.Members;而不是request.auth.uid in request.resource.data.Members;
标签: flutter google-cloud-firestore firebase-security