Unable to fetch user id from firebase

Viewed 23

I am not able to fetch items with user id by typing user?.uid but when I enter the user ID manually it's working fine. I've checked if there is user id before by console logging it and it's showing normally

enter image description here

    console.log(user?.uid)

useEffect(() => {
      try{
        db.collection('users').doc(user?.uid).collection('trades')
        .onSnapshot((querySnapshot) => (
          setTradee(querySnapshot.docs.map(doc => ({
            id: doc.id,
            data: doc.data()
          })))
        ))
    }catch(err){
        alert(err)
    }
     
    },[])

this isn't working

useEffect(() => {
     try{
       db.collection('users').doc('jvchfGPeSaTlDw4POwCFHg1anhz1').collection('trades')
       .onSnapshot((querySnapshot) => (
         setTradee(querySnapshot.docs.map(doc => ({
           id: doc.id,
           data: doc.data()
         })))
       ))
   }catch(err){
       alert(err)
   }
    
   },[])

that works

0 Answers
Related