mysql - Change session object inside callback with express -



mysql - Change session object inside callback with express -

i'm using express , mysql , i'm trying finish login feature.

app.post('/login', function(req, res){ var username = req.body.username; var password = sha1(req.body.password); db.query("select user_id, username users username = '" + username + "' , password = '" + password + "';", function(err, rows, fields){ if(rows.length > 0){ console.log("user " + username + " connected."); req.session.user_id = rows[0].user_id; } });

});

as can see, create query on database , if username , password match, (rows.length >0) seek log user in adding id in session object.

the problem req.session modified within callback , can't find way globally... tried phone call function login(id) didn't work either.

a little help nice, thanks.

the best way authenticate users using mysql db add together passport.js app.

see repo total illustration : node-express-passport-mysql authentication.

if can't work, allow me know , i'll post total code sample when i'm home.

mysql node.js session express login

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -