From ad622a3246d2e56b38cdc53d7a05b39ae31b9b99 Mon Sep 17 00:00:00 2001 From: mohammedsalah7 Date: Sat, 30 Oct 2021 17:39:15 +0200 Subject: [PATCH] edit Suggested changes #15 --- server/controllers/users/login.js | 7 ++++--- server/database/connection.js | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/controllers/users/login.js b/server/controllers/users/login.js index 41e3786..499f678 100644 --- a/server/controllers/users/login.js +++ b/server/controllers/users/login.js @@ -12,13 +12,14 @@ const login = async (req, res, next) => { const { rows } = await checkEmailQuery(email); if (!rows.length) { - throw new Error({ message: 'Invalid email or password' }); + return res.status(400).json({ message: 'Invalid email or password' }); } + const compared = await bcrypt.compare(password, rows[0].password); if (!compared) { - throw new Error({ message: 'Invalid email or password' }); + return res.status(400).json({ message: 'Invalid email or password' }); } - const token = await signToken(email, rows[0].id, rows[0].name, rows[0].phone, rows[0].avater); + const token = await signToken(email, rows[0].id); return res.cookie('token', token).json({ message: 'You are Logged Successfully' }); } catch (err) { if (err.details) { diff --git a/server/database/connection.js b/server/database/connection.js index e2c8673..7ef7a43 100644 --- a/server/database/connection.js +++ b/server/database/connection.js @@ -1,3 +1,4 @@ +require('env2')('.env'); const { Pool } = require('pg'); const {