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

953
Views
Node js TypeError: Cannot read properties of undefined (reading 'email')

I am trying to query mongodb in the login route for users to login to my application.

In the logic of the function, I need to query the submitted user through email param of body request. However, I am getting the error when performing such task.

const login = async(req, res) => {

    const user = await User.findOne({ email: req.body.email })
    const secret = process.env.secret;
    if (!user) {
        return res.status(400).send('the User not found!')
    }
    if (user && bcrypt.compareSync(req.body.password, user.passwordHash)) {

        const token = jwt.sign({
                userId: user.id,
                isAdmin: user.isAdmin

            },
            secret
            , { expiresIn: '1d' } 
        )
        res.status(200).send({ user: user.email, token: token })
    } else {
        res.status(404).send('password Wrong');

    }

}

The error output:

TypeError: Cannot read properties of undefined (reading 'email')
about 4 years ago · Juan Pablo Isaza
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!