Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda