node.js - saving session variables within a callback -
i'm using express.io...
in 1 of routed events, load stored 'vote' database, try set against request's session:
app.io.route('ready', function(req){ if(req.session.username || req.session.twitter_user){ if(!req.session.username){ //makes username store in session. req.session.username = 't_' + req.session.twitter_user.screen_name; } winston.debug(req.session.username + ' connected'); //redders6600 connected. db.getvote(req.session.username, function(err, vote){ //gets votes user. if(!err){ req.session.vote = vote[0].vote; req.io.emit('user data', {username: req.session.username, vote: req.session.vote}); //on client, receive event, , correctly contains username , vote } }); } });
this works okay, but when try access session data routed event, req.session.vote
undefined. req.session.username
gets set correctly.
i know vote[0].vote
not undefined, , it's verified when client side code prints out vote data 'user data' event, i'm quite confused what's happening. thought must context of callback function, fact req.io.emit
working expected makes me doubt that.
not sure else try! appreciated....
i found issue express.io framework - not qualified enough dig code work out why.
instead used session sharing strategy similar 1 outlined here: http://howtonode.org/socket-io-auth
which worked fine , wasn't huge amount of hassle. such don't recommend working express.io.
Comments
Post a Comment