passport auth integrated to login route

This commit is contained in:
Mikayla Dobson
2022-07-05 19:34:39 -05:00
parent 4b4c7a7bb0
commit 8029bf34f4
3 changed files with 10 additions and 10 deletions

View File

@@ -3,10 +3,11 @@ const { LoginService } = require('../services/Auth');
module.exports = (app, passport) => {
app.use('/api/login', loginRouter);
// loginRouter.use(passport.authenticate('local'));
loginRouter.route('/').post(async (req, res, next) => {
console.log('login post got called');
app.use('/api/login', passport.authenticate('local'));
loginRouter.post('/', async (req, res, next) => {
console.log('login called');
const { email, password } = req.body;
/**
@@ -19,10 +20,12 @@ module.exports = (app, passport) => {
* authenticated: boolean,
* user: { email, password }
*/
try {
const data = await LoginService(email, password);
res.status(200).send(data);
const { session, userProfile } = data;
res.status(200).send({ session, userProfile });
} catch(e) {
next(e);
}