So I store my passwords in a database using bcryp.hash when the user signs up.
And then when I try to login, it actually works… until it stops working! I can login maybe 3-4 times using the same login and then the compare method suddenly returns false and I have to create a new user who can log in until he can’t… SUPER WEIRD RIGHT?!
Here’s my code for the signIn route :
exports.signIn = async (req, res, next) => {
try {if (!req.body.email || !req.body.password) res.redirect('/') const user = await User.findOne( {email: req.body.email }) const match = await bcrypt.compare(req.body.password, user.password) if (match) { req.session.email = user.email req.session.userid = user._id res.redirect('/weather') } else { res.redirect('/') }
} catch (err) {
console.log(err)
}
}