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

256
Vistas
"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 Respuestas
Responde la pregunta

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 Denunciar

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