I am trying to use the Socket.IO authorization function to get session data. The problem is that even if I log out and destroy my session, Socket.IO still has old session information, which is clearly not ideal. Any ideas what I am doing wrong in the code below?
io.set('authorization', function (data, accept) { if(data.headers.cookie) { data.cookie = parseCookie(data.headers.cookie); data.sessionID = data.cookie['express.sid']; app.set('mongo-store').get(data.sessionID, function (err, session) { console.log(err, session); if (err || !session) { // if we cannot grab a session, turn down the connection accept('Error', false); } else { // save the session data and accept the connection data.session = session; accept(null, true); } }); } else { return accept('No cookie transmitted.', false); } accept(null, true); });
And here is the connection code:
io.sockets.on('connection', function(socket) { var hs = socket.handshake; console.log('A socket with sessionID ' + hs.sessionID + ' connected!');
Josh smith
source share