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

215
Views
Getting an error on requesting a user details update as Cannot read properties of undefined (reading 'id')

This is my update request for updating a user, but the title is the output that am getting

router.put("/:id", verifyTokenAndAuthorization, async (req, res) => {
  if (req.user.password) {
    req.body.password = CryptoJS.AES.encrypt(
      req.body.password,
      process.env.PASS_SEC
    ).toString();
  }
  try {
    const updatedUser = await User.findByIdAndUpdate(
      req.user.id,
      {
        $set: req.body,
      },
      { new: true }
    );
    res.status(200).json(updatedUser);
  } catch (err) {
    res.status(500).json(err);
  }
});

But the request doesn't go past

const verifyTokenAndAuthorization = (req, res, next) => {
  verifyToken(req, res, () => {
    console.log("req recived for login");
    if (req.user.id === req.params.id || req.user.isAdmin) {
      console.log("req went past verification");
      next();
    } else {
      res.status(403).json("You are not allowed to access!");
    }
  });
};

the problem is in before the output req went past verification

This is printed in my console

req recived for login Error = "Cannot read properties of undefined (reading 'id')" at E:\E-com Project\ver-one-zero-one-api\routes\verifyToken.js:20:18

about 4 years ago · Santiago Gelvez
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!