I need to return true value, so I can catch it in React-Native, but when I try to connect to the account with the right values, I get undefined in the console of the back-end
login : async function (email, password) {
try {
const sqlEmail = "Select * from users where email = ?";
db.query(sqlEmail, email, async (error, results) => {
console.log(results);
if(!results || !(await bcryptjs.compare(password, results[0].password))) {
console.log("tes pas connecté")
return false;
} else {
return true;
}
})
} catch (error) {
console.log(error);
throw new Error (error)
}
},
and this is my route :
router.post('/login', function (req, res) {
userController.login(req.body.email, req.body.password)
.then((result) => {
console.log(result)
res.send(result)
}).catch(err => {
res.send(err)
})
})
Thank you