Flutter 当规则禁止用户以外的任何人阅读时,检查Firestore用户是否存在

Flutter 当规则禁止用户以外的任何人阅读时,检查Firestore用户是否存在,flutter,google-cloud-firestore,firebase-security,Flutter,Google Cloud Firestore,Firebase Security,我为users集合设置了以下规则 match /users/{userId} { allow read, write, update: if request.auth != null && request.auth.uid == userId } 我想检查用户是否存在,但上面的规则不允许我使用。我是否应该允许所有登录用户拥有read权限 FirebaseFirestore.instance .collection('users') .

我为users集合设置了以下规则

   match /users/{userId} {
       allow read, write, update: if request.auth != null && request.auth.uid == userId
   }
我想检查用户是否存在,但上面的规则不允许我使用。我是否应该允许所有登录用户拥有
read
权限

   FirebaseFirestore.instance
   .collection('users')
   .where('email', isEqualTo: snap[index]['email'])
   .get()

尝试创建一个单独的集合,在其中存储所有电子邮件,然后检查电子邮件是否存在,并相应地显示正确的消息。无论是否经过身份验证,所有用户都应该能够访问此集合。

只有当
电子邮件
字段与用户的电子邮件地址匹配时,才能将安全规则设置为匹配。有两件事要考虑……<
  • 规则不是过滤器。您必须显式搜索此文档
  • 这不适用于电话验证用户。如果要处理电话登录,则需要添加另一条规则

  • 你在使用firebase auth吗?是的。Firebase认证<代码>firebase\u验证:^0.20.0确定。我想我能做到。我希望我可以跳过创建一个单独的集合。我需要用户名和用户照片也。因此,每当用户更新其中任何一个时,这个新集合也必须更新。
    match /users/{userId} {
      allow read: if request.auth != null && request.auth.email == resource.data.email
      allow write: if request.auth != null && request.auth.uid == userId
    }