From 70e1a1fb25716edb6fc3b99f851712bcd679c0d1 Mon Sep 17 00:00:00 2001 From: AJ Date: Tue, 25 Apr 2023 01:16:48 +0100 Subject: [PATCH 1/2] Convert email input to lowerCase before check. Convert user email input to lowerCase before check since we saved user email to database using lowercase. --- app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 99c3c8d..c8e8997 100644 --- a/app.js +++ b/app.js @@ -67,8 +67,8 @@ app.post("/login", async (req, res) => { if (!(email && password)) { res.status(400).send("All input is required"); } - // Validate if user exist in our database - const user = await User.findOne({ email }); + // Validate if user exist in our database and also convert email input to lowerCase before check. + const user = await User.findOne({ email.toLowerCase() }); if (user && (await bcrypt.compare(password, user.password))) { // Create token From b99b8a191a1046fab5ac0213db1eb8c7af2908f3 Mon Sep 17 00:00:00 2001 From: AJ Date: Tue, 25 Apr 2023 01:23:59 +0100 Subject: [PATCH 2/2] Convert email input to lowerCase before check. Convert user email input to lowerCase before check since we saved user email to database using lowercase. This is to make sure user email input Case matches what we have saved in database before sending to database for check. --- app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index c8e8997..0b2b097 100644 --- a/app.js +++ b/app.js @@ -67,8 +67,8 @@ app.post("/login", async (req, res) => { if (!(email && password)) { res.status(400).send("All input is required"); } - // Validate if user exist in our database and also convert email input to lowerCase before check. - const user = await User.findOne({ email.toLowerCase() }); + // Validate if user exist in our database + const user = await User.findOne({ email.toLowerCase() }); //ux: convert email input to lowerCase before check if (user && (await bcrypt.compare(password, user.password))) { // Create token