and make them share sessions. I have found examples online and in my "Node up and running" book but somehow I can't get it to work. I must be doing something stupid.
The problem is that in the authorization function of the socket sessionStore.get() always seems to return undefined for both error and session object. Here's my authorize function:
sio.configure(function(){
sio.set('authorization', function(data, accept){
if(data.headers.cookie){
// parseCookie not available anymore
// var cookies = utils.parseCookie(data.headers.cookie);
var cookies = cookie.parse(data.headers.cookie);
data.sessionID = cookies['express.sid'];
console.log("sessionID", data.sessionID);
data.sessionStore = sessionStore;
console.log("store", util.inspect(sessionStore, true, null));
sessionStore.get(data.sessionID, function(err, session) {
if( err || !session) {
console.log("ERROR", err);
console.log("session:", util.inspect(session));
return accept("Invalid session", false);
}
console.log("creating session data");
data.session = new Session(data, session);
accept(null, true);
});
}else{
return accept("No cookie transmitted.", false);
}
});
});
sessionID s:fTZNjPuFIIr5sZvXLCwfR/EQ.6r41SUae3OAQokT58uypmCnajApCyFEfDaWakmlTfYY
store { generate:
{ [Function]
[prototype]: { [constructor]: [Circular] },
[name]: '',
[arguments]: null,
[length]: 1,
[caller]: null },
sessions: { 'fTZNjPuFIIr5sZvXLCwfR/EQ': '{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"}}' } }
ERROR undefined
session: undefined
debug - authorized
warn - handshake error Invalid session
As I see it, the session store clearly holds a session with an id similar to the session id (only up until the "."?), so I don't understand why the get() function returns nothing. Where is that function defined anyway and why doesn't it show up in the util.inspect printout?