I'm trying to log a user with nodeJs and MySql
Here my function to connect a User:
export async function connectUser(email, password, cb) {
console.log('Entry connectuser');
let db = dbConnect();
await db.query('SELECT id, email, password FROM user WHERE email = ?', [email], async (error, result) => {
if (error) return cb(error);
const user = result[0];
console.log(result);
console.log(user.email);
console.log(user.password);
console.log(user.id);
const isValid = await bcrypt.compare(password, user.password);
if (isValid === true) {
const token = jwt.sign({id: user.id, email: user.email }, secret, {expiresIn: 86400 });
return cb(null, token);
}
return cb(new Error('Invalid Credentials'));
});
I get this error: "UnhandledPromiseRejectionWarning: Error: Illegal arguments: object, string" on the bcrypt.compare()
I suppose that it's an error of async/await but i can't fix it... some ideas?