Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
How can I get documents from Firestore for current user?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming your user is logged in, you should be able to access their UID via firebase.auth().currentUser.uid. This question's answers may be useful for more information on getting the current user's ID.

With that, you should be able to do:

const querySnapshot = await getDocs(
    collection(databaseRef, firebase.auth().currentUser.uid)
);

to get the current user's documents.

https://firebase.google.com/docs/reference/js/v8/firebase.auth.Auth#currentuser

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!