I am working with express and socket.io. I have some req.session
variables I wish to access from within socket.io. I read this post on socket.io and session and I am still very confused as to how I can get a req.session
variable.
One way to accomplish this is by using your session store from inside your socket - which will have your all you session variables. This is how I do an authorization (compare cookie ID with session ID from database).
io.set('authorization', function (data, accept) {
if (data.headers.cookie) {
data.cookie = utils.parseCookie(data.headers.cookie);
data.sessionID = data.cookie['connect.sid'].split('.')[0].substring(2);
sessionStore.get(data.sessionID, function (err, session) {
// now you have all session variables
});
}
});