I am trying to find if a user exists in a table given an email and password but I can't get the function to return the right value (currently returns "false"), while the alert inside the function does (alerts "true").
How do I add a callback function to make this work as a synchronous procedure so that the return statement at the end will be true if the user exists?
export const onSignIn = (em, pw) => {
var authorized = false;
db.transaction( tx => {
tx.executeSql(
`select * from users where email = ? and password = ?;`,
[em, pw],
function (transaction, result){
if (result != null && result.rows != null) {
for (var i = 0; i < result.rows.length; i++) {
var row = result.rows.item(i);
if((row.email === em) && (row.password === pw)){
authorized = true;
alert(authorized)
}
}
}
});
});
return authorized
}