|
@ -2,13 +2,22 @@ const express = require('express'); |
|
|
const passport = require('passport') |
|
|
const passport = require('passport') |
|
|
const router = express.Router(); |
|
|
const router = express.Router(); |
|
|
|
|
|
|
|
|
router.get('/auth/login', passport.authenticate('local'), |
|
|
router.post('/auth/login', |
|
|
(req, res) => { |
|
|
(req, res, next) => { |
|
|
res.redirect('/dashboard'); |
|
|
passport.authenticate('local', {}, (err, user, info) => { |
|
|
|
|
|
if (err) |
|
|
|
|
|
return res.status(400).json({errors: err}); |
|
|
|
|
|
if (!user) |
|
|
|
|
|
return res.status(400).json({errors: info}); |
|
|
|
|
|
|
|
|
|
|
|
req.logIn(user, () => { |
|
|
|
|
|
return res.status(200).json({success: `logged in ${user.id}`}); |
|
|
|
|
|
}); |
|
|
|
|
|
})(req, res, next); |
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
router.get('/auth/logout', (req, res) => { |
|
|
router.post('/auth/logout', (req, res) => { |
|
|
req.logout(); |
|
|
req.logout(); |
|
|
res.redirect('/'); |
|
|
res.redirect('/'); |
|
|
}); |
|
|
}); |
|
@ -17,8 +26,4 @@ router.get('/auth/current_user', (req, res) => { |
|
|
res.send(req.user); |
|
|
res.send(req.user); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
router.get('/auth/works', (req, res) => { |
|
|
|
|
|
res.send('Become powerful you have, the dark side in you I sense. Yrsssss.'); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
module.exports = router; |
|
|
module.exports = router; |
|
|