Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
TypeError: Cannot read properties of undefined (reading 'strEmail') How can I solve this problem?

I'm using Express.js writing this code to make a simple login post request :

app.post("/login", (req, res) => {
  res.send(
    {
    isUserRegistered: userLogin(req.body.strEmail, req.body.strPassword),
    }
  )
})

function userLogin(strEmail, strPassword) {
  if (strEmail.includes("mike@gmail.com") , strPassword.includes("12345")) {
    return true;
  } else {
    return false;
  }
}

My Body (raw):

{
    "strEmail":"mike@gmail.com",
    "strPassword":"12345"
}

And the expected response is isUserRegistered:True which depends on what i will pass in the body in postman, Any help?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem is with the scope here.

create a folder called utils and create a userAuthentication.js file there. userAuthentication.js:

function userLogin(strEmail, strPassword) {
  if (strEmail === "mike@gmail.com" && strPassword === "12345") {
    return true;
  } else {
    return false;
  }
}

module.exports = userLogin;

In your app.js or index.js file:

const express = require('express');
const userLogin = require('../utils/userAuthentication');
const app = express();
const port = 4000;

app.use(express.json());

app.post('/login', (req, res) =>{
  const { strEmail, strPassword } = req.body;
  const isAuthenticated = userLogin(strEmail, strPassword);
  if (isAuthenticated) {
    res.status(200).json({
      status: 'Ok',
      message: 'A user successfully logged in'
    });
  } else {
    res.status(500).json({
      status: 'Fail',
      message: 'Wrong credentials'
    }
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda