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
JavaScript
x
12
12
1
exports.editProfilePost = async (req, res, next) => {
2
try {
3
const username = req.user.username;
4
const user = await User.findOneAndUpdate({ username: username }, req.body, {
5
new: true,
6
});
7
res.redirect('/profile');
8
} catch (error) {
9
next(error);
10
}
11
};
12
(error shown) [1]: https://i.stack.imgur.com/xss8j.png
Advertisement
Answer
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.