google firestore auth存在规则

时间:2019-02-12 23:46:30

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

有人对这个认证业务有头脑吗?我有护士(用户)和患者,我想在一些患者记录上给予护士许可。

现在(丢弃有关关系数据库的所有知识)我已经在每个患者下放置了权限,其中每个权限都有用户/护士的ID

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: 
        if get(/databases/$(database)/documents/
          patients/89QL8XXXXFf/
          permissions/KZztXXXXXRf1)!=null;
    }
  }
}

.. ok知道了...

1 个答案:

答案 0 :(得分:0)

    service cloud.firestore {
      match /databases/{database}/documents{ 
          //define the database variable, use it later as $(database)
        match /patients/{patientId}{
            //define variable patientId, use later as $(patientId)
            allow read, write: 
              // if exists(/databases/$(database)/documents //WORKS
              //    /patients/$(patientId)
              //   /permissions/$(request.auth.uid))
              if get(/databases/$(database)/documents //WORKS
                /patients/$(patientId)
                /permissions/$(request.auth.uid)).data.write == true;
         //you have to get(...).data.myProperty 
    }
    // match /{document=**} {
    //  allow read,write: if false;
    // }
  }  
}
相关问题