NodeJS and Socket.io session handling
<p>I'm currently trying to set a session (req.session.username) inside a socket.io connection however it will set it but when I refresh and log out the req.session.username, it logs undefined.</p>

<p>I have my socket.io in a router.get callback:</p>

<pre><code>router.get('/', function(req, res, next) {
var io = req.app.get('socketio');
io.sockets.on('connection', function(socket) {
    socket.on('login', function(data) {
       var username = data.username;
       utils.getUser(data.username, function(obj) {
           if(typeof obj != 'undefined') {
                   if(data.password == obj.password) {
                       req.session.username = username;
                       socket.emit('loginSuccess', {message: "You have successfully logged in, whats up " + data.username + "?"});
                   } else {
                      socket.emit('loginError', {message: "Invalid password, please try again."});
                   }
               } else {
                   socket.emit('loginError', {message: data.username + " does not exist, please create an account."});
               }
       });
   });
});

 console.log(req.session.username);
   res.render('./users/login', {
     logged: false
   });
});
</code></pre>