'bcrypt : data and hash arguments required

I am getting a bcrypt error stating that data and hash arguments are required, referencing line #44 in my routes.js file. From what I can tell, I am passing that information: the first parameter to bcrypt.compare is the user entered password, and the second is the hashed password

let passwordObject = Password.findOne({
    subjectType: 0,
    status: 1,
  });
  if (!!bcrypt.compare(password, passwordObject.value)) {
    return done(null, false, { message: "Incorrect password." });
  }


Solution 1:[1]

findOne is not synchronous. You need to put await on findOne. It seems you are a beginner in Nodejs. Learn promise and async-await.

let passwordObject = await Password.findOne({
    subjectType: 0,
    status: 1,
  });

Solution 2:[2]

adding the await keyword on findOne worked for me

let passwordObject = await Password.findOne({
  subjectType: 0,
  status: 1,
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sandeep Patel
Solution 2 Tobias S.