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

261
Views
"TypeError: Cannot read properties of undefined (reading 'hasOwnProperty')" error

EDIT: PROBLEM SOLVED.

I'm trying to make an update profile page for an Express app with Mongoose, and I got the error "TypeError: Cannot read properties of undefined (reading 'hasOwnProperty')". I am confused how to fix it. Here is my code, thanks

exports.editProfilePost = async (req, res, next) => {
  try {
    const username = req.user.username;
    const user = await User.findOneAndUpdate({ username: username }, req.body, {
      new: true,
    });
    res.redirect('/profile');
  } catch (error) {
    next(error);
  }
};

(error shown) [1]: https://i.stack.imgur.com/xss8j.png

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

0

The req.user could be undefined. To debug, add the checking:

let username = "";
if (typeof req.user !== "undefined") {
   username = req.user.username;
}
about 4 years ago · Juan Pablo Isaza Report

0

So... idk why this works but I forgot to make the profile picture push to cloudinary. Somehow, not pushing to cloudinary made the req.body empty, resulting in the error.

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!