以下是注册路线
router.post("/register", function(req, res){
var newUser= new User({username:req.body.username});
User.register(newUser,req.body.password, function(error,user){
if(error){
req.flash("error", error.message);
return res.render("register.ejs");
}else{
passport.authenticate("local")(req, res ,function(){
req.flash("success","Welcome to PhotoDiary, " + user.username);
res.redirect("/diary");
});
}
});
});
以下是本地护照
app.use(function(req, res, next){
res.locals.currentUser = req.user;
res.locals.error = req.flash("error");
res.locals.success = req.flash("success");
next();
我将 flash-connect 放入寄存器路由 req.flash("error", error.message); 当我注册时,它会在另一次刷新后显示消息,而不是在同一页面上