i tried req.login which is a passport method which i think its used when we sign up only but it didn
t work and i see this solution Passport-Local-Mongoose – When I Update A Record's Username, I'm Logged Out, Why? but it didn`t work and
async (req, res, next) => {
const {id} = req.params;
if (req.file) {
const {path, filename} = req.file;
const foundUser = await User.findByIdAndUpdate(id, {
profileImage: {profileUrl: path, filename},
});
}
const foundUser = await User.findByIdAndUpdate(id, req.body.user);
req.logIn(foundUser, function (err) {
if (err) {
return next(err);
}
return res.redirect("/user/" + foundUser.username);
});
}
);