app.post('/login', function(req, res) {
passport.authenticate('local', { session: false }, (err, user, info) => {
if(err || !user) {
const err = {};
err.status = 400;
err.code = 'Err';
return res.json(err);
}
return res.redirect('/?access_token=' + user.token);
});
}));
app.get('/login', function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
if (err) { return next(err); }
if (!user) { return res.redirect('/login'); }
req.logIn(user, function(err) {
if (err) { return next(err); }
return res.redirect('/users/' + user.username);
});
})(req, res, next);
});