christmas/routes/login/index.js
2018-11-20 14:19:58 -05:00

29 lines
No EOL
551 B
JavaScript

const passport = require('passport');
const express = require('express');
module.exports = () => {
const router = express.Router();
router.get('/',
(req, res) => {
if (req.isAuthenticated()) {
res.redirect('/');
} else {
res.render('login');
}
}
);
router.post(
'/',
(req, res, next) => {
next();
},
passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/login',
failureFlash: 'Invalid username or password'
})
);
return router;
};