Skip to content

Commit

Permalink
edit Suggested changes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammedsalah7 committed Oct 30, 2021
1 parent 7116e47 commit ad622a3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/controllers/users/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions server/database/connection.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('env2')('.env');
const { Pool } = require('pg');

const {
Expand Down

0 comments on commit ad622a3

Please sign in to comment.