app.post("/register", isLogged ,function(req, res){
var newUser = new User(
{
username: req.body.username,
firstname: req.body.firstname,
lastname: req.body.lastname,
avatar: req.body.avatar,
email: req.body.email
});
User.register(newUser, req.body.password, function(err, user){
if(err){
return res.redirect("/register");
console.log(err);
}
passport.authenticate("local")(req, res, function(){
req.flash("success","Welcome to the pharmacist's diary " + user.username+ "!" );
res.redirect("/records");
});
});
为什么这条路线无法正常工作,并继续发送相同的信息'错误请求'。
function isLogged(req, res, next){
if(req.isAuthenticated()){
req.flash("error", "You are already logged in!");
res.redirect("/records");
}else {
return next();
}
} 这是isLogged代码(使用中间件)