【发布时间】:2020-07-17 09:49:37
【问题描述】:
我正在尝试从私人设备查询一些数据。我的规则设置如下:
match /private_devices/{device} {
function userHasKey() {
return request.auth != null && exists(/databases/$(database)/documents/users/$(request.auth.uid)/keys/$(device));
}
allow read: if (userHasKey())
}
我的颤振代码:
Stream<QuerySnapshot> getPrivateDevices(List<String> keyList) {
return private.where('UDID', whereIn: keyList).snapshots();
}
我使用列表从以下位置导入密钥:
Stream<QuerySnapshot> getUserKeys(User user) {
return users.document(user.uid).collection('keys').snapshots();
}
还有我的用户规则:
match /users/{userId} {
allow read, write: if (request.auth != null && request.auth.uid == userId)
}
match /users/{userId}/keys/{key} {
allow read, write: if (request.auth != null && request.auth.uid == userId)
}
编辑:我的收藏参考:
final CollectionReference devices = Firestore.instance.collection("devices");
final CollectionReference users = Firestore.instance.collection("users");
final CollectionReference private = Firestore.instance.collection("private_devices");
我在控制台中收到以下权限错误:
Listen for Query(private_devices where UDID in [F8MXi2JzwYvIAoVRYG5f] order by __name__) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
I/System.out(27625): com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.
我还在规则操场上测试了我的规则,一切正常。我知道这与查询有关,但不知道如何前进。
我还注意到,当我尝试使用private.document(keyList[0]).get() 获取单个文档时,我实际上取回了数据。
欢迎任何帮助,在此先感谢您。
【问题讨论】:
-
这里没有足够的代码来查看您的实际查询是什么。请显示完整查询,让我们了解它们如何映射到您定义的规则。我们只是无法判断您的查询是否真的符合规则。
-
没有其他查询。只是收集参考。
-
无论如何,显示完整的代码。这里没有足够的信息。例如,我们看不到您的代码中的
private和users是什么。应该有足够的信息让任何人都可以用来重现该行为。 -
我已经添加了引用到这个问题的每一行。
标签: flutter google-cloud-firestore firebase-security