我使用护照js来验证我的用户,但我在仪表板中更改用户名时遇到问题,每当用户更改用户名并点击更新按钮时,他们会自动注销并重定向到登录页。有没有什么方法可以在更新用户名后再进行身份验证,而无需再次登录。我尝试的那些返回Bad请求。
router.put("/dashboard/:id/update", isLoggedIn, isVerified, function(req,res){
User.findByIdAndUpdate(req.params.id, req.body.updated, function(error, updated){
if(error){
console.log("error occured " + error);
return res.redirect("/dashboard")
} else {
passport.authenticate("local")(req, res, function(){
res.redirect("/dashboard/" + req.params.id + "/view")
});
}
})
})
Middle Ware
function isLoggedIn(req, res, next){
if(req.isAuthenticated()){
return next();
}
req.flash("error", "Please login first to do that")
res.redirect('/login');
}