简体   繁体   中英

I can`t read the data after I update my rules on firestore (React Native)

the rules I set is allow read: if resource.data.uid == request.auth.uid;

how I call it is like this

return async (dispatch) => {
    await firebase
      .firestore()
      .collection("patients")
      .doc(firebase.auth().currentUser.uid)
      .collection("patient")
      .orderBy("creation", "desc")
      .get()
      .then((result) => {
        let Patients = result.docs.map((doc) => {
          const data = doc.data();
          const id = doc.id;
          return { id, ...data };
        });
        dispatch({ type: GET_PATIENTS, Patients });
      });
  };

How can i fix it?

firebase rule

 match /databases/{database}/documents {
    match /patients/{patientsID}{
        match /patient/{patientID}{
        allow read: if resource.data.uid == request.auth.uid;
        allow create: if request.resource.data.uid == request.auth.uid;
        allow update: if request.resource.data.uid == request.auth.uid;
        allow delete: if resource.data.uid == request.auth.uid;
        match /diagnostic/{diagnosticID}{
          allow read: if true;
          allow write: if request.resource.data.uid == request.auth.uid;
        }
      }
    }
  }
}

image for the data

https://1drv.ms/u/s?Ag7uBMx2FuEijuILje2xJIv8RawcFA?e=Gy6jeC

Rules don't filter data on their own. Instead they merely ensure that the data that is being requested matches your rules.

So your query needs to match the rules, which means they also need to filter by UID:

  .collection("patient")
  .orderBy("creation", "desc")
  .where("uid", "==", firebase.auth().currentUser.uid)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM