0

I have a Security role in fireStore like this

 allow read: if resource.data.uid == request.auth.uid;

and I am trying to git the data like this

export function GetPatients(limit) {
  return async (dispatch) => {
    await firebase
      .firestore()
      .collection("patients")
      .doc(firebase.auth().currentUser.uid)
      .collection("patient")
      .orderBy("creation", "desc")
      .where("uid", "==", firebase.auth().currentUser.uid && "importent" ,"==" ,true)
      .limit(limit)
      .onSnapshot((result) => {
        let Patients = result.docs.map((doc) => {
          const data = doc.data();
          const id = doc.id;
          return { id, ...data };
        });
        lastPatient = result.docs[result.docs.length - 1];
        dispatch({ type: GET_PATIENTS, Patients });
      });
  };
}

do I need to change the roles or there is something wrong with how a querying the data ?

the error I am getting is

Error in snapshot listener: FirebaseError: Missing or insufficient permissions. –

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Osama Tab
  • 51
  • 7
  • You have to enable permission. Refer this [stackoverflow question](https://stackoverflow.com/questions/46590155/firestore-permission-denied-missing-or-insufficient-permissions) – Ragul CS Mar 26 '21 at 11:32
  • I already done so but still does not work when i want to show it just for the user who wrote it allow read: if resource.data.uid == request.auth.uid; I want to show only what he set to important – Osama Tab Mar 26 '21 at 11:57

1 Answers1

2

This is not how you add multiple conditions to a query:

.where("uid", "==", firebase.auth().currentUser.uid && "importent" ,"==" ,true)

Instead, call where once for each condition. So:

.where("uid", "==", firebase.auth().currentUser.uid)
.where("importent" ,"==" ,true)
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807