This is my code.
router.route("/login").post((req, res) => {
const email = req.body.email;
const password = req.body.password;
Account.find().then((account) => {
account.forEach((eachAcc) => {
if (eachAcc.email.toUpperCase() === email.toUpperCase()) {
bcrypt.compare(password, eachAcc.password, function (err, result) {
if (result == true) res.status(200).json("Login Successful");
else if (err) res.status(400).json("Error: " + err);
});
}
});
res.status(400).json("Invalid email or password");
});
});
But I am always getting Invalid email/ password, I want it to be printed only when loop has completed and email/ password didn't match.
Please help.