firebase - 尝试按用户uid firebase分离数据?

标签 firebase flutter dart google-cloud-firestore firebase-security

我的规则中有此功能,但无法正常工作,几周前才开始使用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/

相关文章:

ios - Firebase 查询没有为 TableView 填充数组。我该如何解决这个问题?

dart - 预加载网络镜像以避免加载时间

flutter - 如果 Flutter 中的有状态小部件可以实现同样的功能,为什么我们需要无状态小部件?

flutter - 重构问题: Extract as widget/method/variable. ..有什么优缺点?

dart - Flutter 中带有调整下拉箭头图标的全宽 DropdownButton

ios - 我们如何将数据写入 firebase 实时数据库?尽管启用了读/写,但似乎不起作用

java - Firebase 存储错误尝试将数据插入我的数据库

android - flutter 运行未完成

arrays - 如何从渲染列表中访问对象键?

javascript - 如何部署在文件上传到 Firebase 存储时运行的 Firebase 函数?