You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
755 B
29 lines
755 B
const express = require('express');
|
|
const passport = require('passport')
|
|
const router = express.Router();
|
|
|
|
router.post('/auth/login',
|
|
(req, res, next) => {
|
|
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.post('/auth/logout', (req, res) => {
|
|
req.logout();
|
|
res.redirect('/');
|
|
});
|
|
|
|
router.get('/auth/current_user', (req, res) => {
|
|
res.send(req.user);
|
|
});
|
|
|
|
module.exports = router;
|
|
|