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

442
Views
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 answers
Answer question

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 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!