Passport はログインセッションを確立するための login() 関数を req のメソッドとして
用意しています。( lonIn() としてエイリアスも貼られています。)
Passport exposes alogin()function onreq(also aliased aslogIn()) that can be used to establish a login session.
req.login(user, function(err) {
if (err) { return next(err); }
return res.redirect('/users/' + req.user.username);
});
ログイン操作が完了すると、user は req.user に割り当てられます。
When the login operation completes,userwill be assigned toreq.user.
注意: passport.authentocate() ミドルウェアは自動的に req.login() を実行します。
この関数は主にユーザーのサインアップのために用いられ、その際に req.login() 関数を実行し
自動的にログインを行います。
Note:passport.authenticate()middleware invokesreq.login()automatically. This function is primarily used when users sign up, during whichreq.login()can be invoked to automatically log in the newly registered user.