I'm working on a pluralsight module for authentication and I'm stuck at the point of actually trying to authenticate users.
connection.query('SELECT * FROM users WHERE username LIKE ?', [data.username], function (err, results) {
if (err) throw err;
var results=(JSON.stringify(results));
console.log(results);
console.log(results.password)
if(results.password === password){
var user = results;
// done(null, user);
} else {
console.log('else')
// done('Bad password', null)
}
});
err
results
JSON.stringify
[ RowDataPacket { id: 12, username: 'qqq', password: 'qqq' } ]
[{"id":12,"username":"qqq","password":"qqq"}]
results.username
results.password
console.log(results[0].username);
console.log(results[0].password);
undefined
Try looping through the result set like this:
for (var i = results.length - 1; i >= 0; i--) {
var current = results[i];
console.log(current);
}
Then if all goes well, you should be able to check each variable with:
current.username
etc..