How can I get documents from Firestore for current user?

Viewed 553

I'm trying do display data from Firestore database in my component.

This is my function:

const getData = async () => {
    const data = [];

    const querySnapshot = await getDocs(
      collection(databaseRef, "mK7DFNJgRAPmtvgrZh7X6AOj8cR2")
    );
    console.log(querySnapshot);
    querySnapshot.forEach((doc) => {
      console.log(doc.id, " => ", doc.data().Title);
      data.push({
        About: doc.data().About,
        Title: doc.data().Title,
        Who: doc.data().Who,
      });
    });
    setData(data);
  };

Collection ID = Current logged in User. I want to display every document. Everything works fine but insteed of passing hard-coded string here:

      collection(databaseRef, "mK7DFNJgRAPmtvgrZh7X6AOj8cR2")

I would like to pass variable where I store my UID.

Is there any way to do that?

1 Answers
Related