function isLoggedIn(req,res,next){ // middleware
if(req.isAuthenticated()){
return next();
}
res.redirect("/login");
console.log("It's not working");
}
app.get("/campgrounds/:id/comments/new", isLoggedIn ,function(req,res){
Campground.findById(req.params.id, function(err, campground){
if(err){
console.log(err);
}else{
res.render("comments/new.ejs",{campground:campground});
console.log("It's working")
}
});
});
app.post("/campgrounds/:id/comments", isLoggedIn , function(req,res){
Campground.findById(req.params.id, function(err,campground){
if(err){
console.log(err);
res.redirect("/campgrounds");
}else{
Comment.create(req.body.comment, function(err,comment){
if(err){
console.log(err);
}else{
campground.comments.push(comment);
campground.save();
res.redirect("/campgrounds/" + campground._id);
}
});
}
});
});
每当我尝试在用户登录时添加评论时,它会向我显示错误“它无法正常工作”,如此处的console.log。请帮忙