passport auth integrated to login route
This commit is contained in:
@@ -20,7 +20,7 @@ module.exports = (app) => {
|
|||||||
|
|
||||||
passport.use(new LocalStrategy(async (email, password, done) => {
|
passport.use(new LocalStrategy(async (email, password, done) => {
|
||||||
try {
|
try {
|
||||||
const response = await LoginService(email, password);
|
const response = await LoginService({ email: email, password: password });
|
||||||
return done(null, response);
|
return done(null, response);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return done(e);
|
return done(e);
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ const { LoginService } = require('../services/Auth');
|
|||||||
|
|
||||||
module.exports = (app, passport) => {
|
module.exports = (app, passport) => {
|
||||||
app.use('/api/login', loginRouter);
|
app.use('/api/login', loginRouter);
|
||||||
// loginRouter.use(passport.authenticate('local'));
|
|
||||||
|
|
||||||
loginRouter.route('/').post(async (req, res, next) => {
|
app.use('/api/login', passport.authenticate('local'));
|
||||||
console.log('login post got called');
|
|
||||||
|
loginRouter.post('/', async (req, res, next) => {
|
||||||
|
console.log('login called');
|
||||||
const { email, password } = req.body;
|
const { email, password } = req.body;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,10 +20,12 @@ module.exports = (app, passport) => {
|
|||||||
* authenticated: boolean,
|
* authenticated: boolean,
|
||||||
* user: { email, password }
|
* user: { email, password }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await LoginService(email, password);
|
const data = await LoginService(email, password);
|
||||||
res.status(200).send(data);
|
const { session, userProfile } = data;
|
||||||
|
|
||||||
|
res.status(200).send({ session, userProfile });
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
next(e);
|
next(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,10 +30,7 @@ async function LoginService(email, password) {
|
|||||||
userProfile: fullUserProfile.rows[0]
|
userProfile: fullUserProfile.rows[0]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
throw new Error("Auth unsuccessful.");
|
||||||
session: 'not found',
|
|
||||||
userProfile: 'not found'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
await client.query("ROLLBACK");
|
await client.query("ROLLBACK");
|
||||||
|
|||||||
Reference in New Issue
Block a user