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

443
Vistas
Firestore: getDocs, getDoc; Uncaught TypeError: Cannot read properties of null

I'm using firestore to store some data in two collections ("users" and "requests"). I have some functions in my javascript code that allow me to read and write the data in the database, and they work fine. However, when I use the same methods in the following code, I get two errors:

  • Uncaught TypeError: Cannot read properties of null (reading 'email') at HTMLDocument
  • Uncaught (in promise) TypeError: Cannot read properties of null (reading 'addEventListener') at Array.forEach () at He.forEach.

I've tried several options but they don't work and I'm very confused, because the code I use to access the data works fine in other parts of the program.

document.addEventListener('DOMContentLoaded', function() {

    const user = auth.currentUser;

    getDocs(collection(db, "requests")).then(querySnapshot => {
        querySnapshot.forEach((doc) => {
            document.getElementById(doc.id).addEventListener('click', function() {
                openAcceptModal();
            })
        })  
    })
    getDoc(doc(db, "users", user.email)).then(docSnap => {
        if (docSnap.exists()) {
            const uEmail = docSnap.get("email");
            const uName = docSnap.get("name");
            const uPost = docSnap.get("post");
            const uRating = docSnap.get("rating");
            const uTeam = docSnap.get("team");
            console.log(uEmail,uName,uPost,uRating,uTeam);
        }
    })
})

Does anybody have any idea of what's wrong with this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The First error “Cannot read properties of null (reading 'email') at HTMLDocument” is mainly caused if the current user is not signed in and it will take the null value, so the user will not be able to access the ‘email’. You need to check whether the user is signed in or not, you can refer to the stackoverflow answer where an example has been provided.

The second error “Cannot read properties of null (reading 'addEventListener')” is mainly resolved by checking the variable before adding an event listener. You can refer to the stackoverflow answer where the issue has been resolved by the Rob.

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