我的规则中有此功能,但无法正常工作,几周前才开始使用Firebase
match /pets/{owner} {
allow read, write: if request.auth.uid == owner
}
这是我用来从集合中获取数据的代码:
Stream<List<Pet>> get pets{
print(userUid);
return petsCollection.where('owner', isEqualTo:
userUid).snapshots().map(_petListFromSnapshot);
}
即时通讯使用打印,看看我是否从当前用户获取该查询的uid,但它为null。在代码的不同部分中,我已经将创建文档的人的uid添加到集合中。
我想说的是,我需要有关如何仅获取当前用户数据的建议。
最佳答案
您不能使用安全规则来过滤结果
Once you secure your data and begin to write queries, keep in mind that security rules are not filters. You cannot write a query for all the documents in a collection and expect Cloud Firestore to return only the documents that the current client has permission to access.
https://firebase.google.com/docs/firestore/security/rules-conditions?authuser=0#rules_are_not_filters
使用过滤器获取当前用户相关的文档。
关于firebase - 尝试按用户uid firebase分离数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61216456/