为什么此Firebase查询有效而另一个无效

时间:2020-05-02 00:30:29

标签: firebase google-cloud-firestore firebase-security

运行此查询时

self.db.collection("strokedata").whereField("uid", isEqualTo: coachid!).addSnapshotListener { (querySnapshot, err) in

有了这些规则,

  rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {

       function isSignedIn() {
              return request.auth != null;
            }

          match /strokedata/{document} {

          allow write: if isSignedIn() && document == request.auth.uid;
          allow read: if document == request.auth.uid || request.auth.uid == resource.data.uid; 

          }

         match /users/{document} {

          allow create: if request.auth.uid != null;
          allow read: if request.auth != null;
          allow write: if document == request.auth.uid; 
      }
    }
  }

resource.data.uid中的uid文本代码变为绿色,并且查询有效。

但是,当我运行此查询时

self.db.collection("strokedata").whereField("coachuid", isEqualTo: coachid!).addSnapshotListener { (querySnapshot, err) in

使用这些规则,它将不起作用,在这种情况下,指导代码不会在规则中变为绿色。

  rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {

       function isSignedIn() {
              return request.auth != null;
            }

          match /strokedata/{document} {

          allow write: if isSignedIn() && document == request.auth.uid;
          allow read: if document == request.auth.uid || request.auth.uid == resource.data.coachuid; 

          }

         match /users/{document} {

          allow create: if request.auth.uid != null;
          allow read: if request.auth != null;
          allow write: if document == request.auth.uid; 
      }
    }
  }

我有一些可行的方法,但是我很好奇为什么coachuid查询不会变成绿色并且规则每次都失败。

0 个答案:

没有答案