From cb622c4221ce39c28da9ef9e9f14c23296c4c0ae Mon Sep 17 00:00:00 2001 From: V S Tharunika <1vstharu279@gmail.com> Date: Tue, 29 Dec 2020 19:55:57 +0530 Subject: [PATCH] adding endpoint for log in --- .../src/controllers/AuthenticationController.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server/src/controllers/AuthenticationController.js b/server/src/controllers/AuthenticationController.js index 6209cfb2..ae68a73d 100644 --- a/server/src/controllers/AuthenticationController.js +++ b/server/src/controllers/AuthenticationController.js @@ -23,14 +23,23 @@ module.exports={ } }) if (!user) { - res.status(403).send({ + return res.status(403).send({ error: 'The login information was incorrect' }) } - res.send(user.toJSON()) + const isPasswordValid = password === user.password + if(!isPasswordValid) { + return res.status(403).send({ + error: 'The login information was incorrect' + }) + } + const userJson = user.toJSON() + res.send({ + user: userJSON + }) }catch (err){ - res.status(400).send({ - error: 'This email account is already in use.' + res.status(500).send({ + error: 'An error has occured trying to log in' }) } } -- GitLab