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

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

0

You should add this code

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