作成しようとしているログイン ページに、かなり基本的なエラー メッセージを実装しようとしています。投稿リクエストのコードは次のとおりです。
app.post('/login',function(req,res){
User.findOne({username:req.body.user.username},function(err,info){
if(err){
req.flash('error','There was an error on our end. Sorry about that.');
res.redirect('/');
}
if(info==null){
req.flash('error', 'Incorrect Username. Please try again, or make an account');
res.redirect('/login');
}
else{
if(req.body.user.password==info.password){
res.redirect('/users/' + info.username);
}
else{
req.flash('error', 'Incorrect Password');
res.redirect('/login');
}
}
});
});
リダイレクトは発生しますが、null ケースをトリガーしてもエラー メッセージは表示されません。ルートの get メソッドは次のとおりです。
app.get('/login',function(req,res){
res.render('login',{
title: 'Login'
});
});