I have a user
user = new User('name','pwd');
which should contain a valid
property
var User = module.exports = function User(username, password){
db.query('MATCH (user) WHERE user.username={username} RETURN user',
{username:username},
function(err,result){ // << The callback
if(err) return console.log('error: '+err);
if(result[0])
this.valid=true; // << this.value
if(result[0].user.data.hash == crypto.createHash('sha256').update(password+result[0].user.data.salt,'utf8').digest('hex'))
this.authenticated=true;
}
);
}
But since this.valid
is called from within a callback of the db.query
, it doesn't execute before the new
object is already returned without this.valid
.
What can I do?