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

278
Views
TypeError: Cannot read properties of undefined (reading 'email')

I'm trying to authenticate user. Sign-up is working fine but in sign-in req.body.email is undefined and I can't figure out why. Here is my code for sign-in:

router.post('/signin',(res,req,next)=>{
    User.findOne({ email: req.body.email })
    .exec()
    .then(user => {
        if(user.length<1){
            return res.status(401).json({
                message: 'Auth Failed'
            })
        }
        bcrypt.compare(req.body.password, this.user[0].password, (err,result)=>{
            if(err){
                return res.status(401).json({
                    message: 'Auth Failed'
                });
            }
            if(result){
                return res.status(200).json({
                    message: 'Auth Successful'
                });
            }
            res.status(401).json({
                message: 'Auth Failed'
            });
        })
    })
    .catch(err => {
        console.log(err);
        res.status(500).json({
            error: err
        });
    })
    
})

On Postman:

{
    "email": "test@gmail.com",
    "password": "12345"
}

Console Error:

TypeError: Cannot read properties of undefined (reading 'email')
    at C:\Users\SJPC\auth\routes\user.route.js:62:37
    at Layer.handle [as handle_request] (C:\Users\SJPC\auth\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\SJPC\auth\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\SJPC\auth\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\SJPC\auth\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\SJPC\auth\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\Users\SJPC\auth\node_modules\express\lib\router\index.js:341:12)
    at next (C:\Users\SJPC\auth\node_modules\express\lib\router\index.js:275:10)
    at Function.handle (C:\Users\SJPC\auth\node_modules\express\lib\router\index.js:174:3)
    at router (C:\Users\SJPC\auth\node_modules\express\lib\router\index.js:47:12)

I have tried req.query.email but it also thrown the same error.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should add this code

app.use(express.json())
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!