diff --git a/controllers/auth.js b/controllers/auth.js index 47ae245..6db904c 100644 --- a/controllers/auth.js +++ b/controllers/auth.js @@ -224,17 +224,25 @@ module.exports.postSignin = async (req, res, next) => { console.log("req.body", req.body); let user = await User.findOne({ email }); if (isGoogle) { - user.isVerified = true; - user = await user.save(); - const isMatched = await bcrypt.compare(password, user.password); - if (isMatched) { - const token = jwt.sign({ _id: user._id }, JWT_secret); - res.json({ - token: token, - }); + if (user) { + user.isVerified = true; + user = await user.save(); + const isMatched = await bcrypt.compare(password, user.password); + if (isMatched) { + const token = jwt.sign({ _id: user._id }, JWT_secret); + res.json({ + token: token, + }); + } else { + res.json({ + message: "email and password doesn't match", + type: "error", + }); + return; + } } else { res.json({ - message: "email and password doesn't match", + message: "User Doesn't Exists", type: "error", }); return;