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

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

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