I'm making a logging system in NodeJS with MySQL DB. First I do the connection like this:
const con = mysql.createConnection({
host : 'localhost',
user : 'dbuser',
password : 'dbpass',
database : 'dbname',
port : 3306,
multipleStatements : true
});
Then when I do a query to get users data I do the following query.
var user;
con.query('SELECT * FROM users WHERE email = ?', email, function(err, rows) {
if (err) throw err;
else {
user = rows[0];
}
});
But when I finally compare any of the fields of the user returned I get an error:
if (tools.hashPassword(password) == user.hash) {
// Do stuff
}
The error is TypeError: Cannot read property 'hash' of undefined. Any suggestion?