I have a function that compares the email and password of the one provided on a sign in page. The function finds one document in a database with the provided email, then compares the password using bcrypt.compare()
. The only problem is I keep getting the error UnhandledPromiseRejectionWarning: Error: data and hash arguments required
. Below is my function, any ideas why I’m getting the error? I have a feeling it has something to do with bcrypt trying to compare the passwords before the document is found:
const validateLogin = () => {
Dev.findOne({ email: providedEmail }).then(
async (devBody) => {
if (
await bcrypt.compare(
providedPassword,
stringifiedBody.password
)
) {
console.log("That's them!");
}
}
);
};
Note: providedEmail
and providedPassword
are both variables assigned to req.body which gets the inputs provided by the user.