Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

441
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda