'get record of firestore database with same userid in firestore with login user for edit - react firestore

i have stored login user in localstorage.

useEffect(() => {
const getUsers = async () => {

  const loginUser = JSON.parse(localStorage.getItem("user"));
  
  let qt = doc(db, "todoData", id);
  
  //const qu = query(qt, where("userId", "==", loginUser.uid))  
  
  const querySnapshot = await getDoc(qt);

  if (querySnapshot.exists()) {
    console.log(querySnapshot.data());
  } else {
    console.log("No such document");
  }

  setState({
    name: querySnapshot.data().name,
    desc: querySnapshot.data().description,
    date: querySnapshot.data().completeDate,
    isCompleted: querySnapshot.data().isComplete,
  });

};

getUsers();  }, []);

i can't understand how can i do. in where condition userId is in firebase firestore.

and how to use where condition to edit and delete only those data who login user.



Solution 1:[1]

i just get this answer

match /todoData/{Id} {   
    allow update , delete: if request.auth != null; && request.auth.uid == resource.data.Id;
}

just make a rule update in Cloud Firestore rule.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rakesh mokariya