I am trying to add in the Node.js id to session retrieved from the database. I edits the steam-login for this purpose, but everything except the passing of the id works. I know why it does not work. This is because the query in node.js is asynchronous. Unfortunately, I do not know how to solve it, to return it in a function.
req.user = user;
connection.query("select * from users where steamid = "+user.steamid, function(err, row){
if(err) {
throw err;
} else {
req.user.id = row[0].id;
//And now when i trying to console.log(req.user.id) i will se the id from database.
}
});
//But here when i try console.log(req.use.id) i see undefined.
I need to set req.user.id = id
from database.
i can't do it like up, because this dont work.