In you useEffect you can add auth check and call firestore.
useEffect(() => {
let firestoreCall;
if(auth) {
firestoreCall = firebase
.firestore()
.collection("richieste")
/* .where("userId", "==", props.loggedIn.uid) */
.onSnapshot((snapshot) => {
const newRichieste = snapshot.docs.map((richiesta) => ({
id: richiesta.id,
...richiesta.data(),
}));
let nuoveRichieste = newRichieste.sort(function (a, b) {
return a.timestamp - b.timestamp;
});
setRichieste(nuoveRichieste.reverse());
setInCaricamento(false);
});
}
return () => {
firestoreCall?.();
};
}, [auth]);
CLICK HERE to find out more related problems solutions.