Node.js - Express.io: Different session saving in different browsers -
how , if sessions correct saved differs in node.js' express.io (all in latest version) different browsers. how fix misbehavior?
code:
app.get('/home', function(req, res) { req.session.variable = 'value'; req.session.save(function() { console.log(req.session); }); res.send('<script src="/socket.io/socket.io.js"></script>\ <script>var socket = io.connect();</script>\ home content'); }); app.io.route('disconnect', function(req) { console.log('-------------------------------'); console.log(req.session); req.session.variable = ''; req.session.save(function() { console.log(req.session); console.log('-------------------------------'); }); });
situation: i'm on /home
page , reload page. output of console in every(?) browser except chrome after reload:
{ cookie: { path: '/', _expires: mon may 19 2014 01:40:59 gmt+0200, originalmaxage: 31536000000, httponly: true }, variable: 'value' } // reload: ------------------------------- { cookie: { originalmaxage: 31536000000, expires: '2014-05-18t23:40:59.399z', httponly: true, path: '/' }, variable: 'value', touch: [function], resetmaxage: [function], save: [function], reload: [function], destroy: [function], regenerate: [function] } { cookie: { originalmaxage: 31536000000, expires: '2014-05-18t23:40:59.399z', httponly: true, path: '/' }, variable: '', touch: [function], resetmaxage: [function], save: [function], reload: [function], destroy: [function], regenerate: [function] } ------------------------------- { cookie: { path: '/', _expires: mon may 19 2014 01:41:03 gmt+0200, originalmaxage: 31536000000, httponly: true }, variable: 'value' }
in chrome:
{ cookie: { path: '/', _expires: mon may 19 2014 00:43:37 gmt+0200, originalmaxage: 31536000000, httponly: true }, variable: 'value' } // reload { cookie: { path: '/', _expires: mon may 19 2014 00:43:37 gmt+0200, originalmaxage: 31536000000, httponly: true }, variable: 'value' } ------------------------------- { cookie: { originalmaxage: 31536000000, expires: '2014-05-18t23:36:58.926z', httponly: true, path: '/' }, variable: 'value', touch: [function], resetmaxage: [function], save: [function], reload: [function], destroy: [function], regenerate: [function] } { cookie: { originalmaxage: 31536000000, expires: '2014-05-18t23:36:58.926z', httponly: true, path: '/' }, variable: '', touch: [function], resetmaxage: [function], save: [function], reload: [function], destroy: [function], regenerate: [function] } -------------------------------
may bug of chrome , not express.io? it's weird log order different in chrome other browser.
what need session variable should deleted/empty if user navigates away page (which sets variable).
i think solved problem long time ago setting setting sync disconnect on unload on client side that:
var socket = io.connect('your-socket-url.com', { 'sync disconnect on unload': true });
Comments
Post a Comment