I'm trying to get user.foo and user.bar instead of an array of values from sqlite:
let user: any = await db.query('SELECT id, email, hashed_password FROM users WHERE email = ?', [body.email]);
if (!user || !user.length) {
context.response.status = 400;
context.response.body = { message: "User not found" };
return;
}
user = user[0];
console.log(user);
console.log(body.password, user[2]);
const comparison = await bcrypt.compare(body.password, user[2]);
console.log('comparison: ', comparison);
Is this possible?
edit: I am still getting an error here that query didn't return any rows even though its in a try catch (and the rows DO exist)
try {
const query = db.prepareQuery<[number, string]>("SELECT id, email, hashed_password FROM users WHERE email = ?",
[body.email],
);
user = query.oneEntry();
} catch(err) {
console.error(err);
context.response.status = 400;
context.response.body = { message: "User not found" };
return;
}
console.log('user: ', user);