0

I am using socket.io along with express sessions. I am using their middleware to get the cookie in the header, like:

io.use(function(socket, next) {
console.log(socket.handshake.headers.cookie);
next();

}); which puts this to the console:

io=ELJQk5v7q-jjZ5d_AAAA; connect.sid=s%3A17faf004-46c7-4219-9dac-81853ada8cab.ZzFPL%2BpHY9hNxEMDcLesnGEbuZyU9mOwVBZNEBuHzKA

Ok, great! Now I have the cookie, but how do I get the information out of it. I am thoroughly confused.

My session is initialized like this:

app.use(session({ //using express-session
genid: function(req) {
    return uuid.v4();
},
secret: 'operation',
resave: false,
saveUninitialized: true

}));

I've searched far and wide over a simple explanation, but I have not found one. Is it required that I use sessionStore? If so why? I've tried different modules that are supposedly set up to handle this, but so far none of them have worked. I am using MongoDB, so I wouldn't mind storing them there if it is necessary, but I want to avoid using Redis to handle this as others have.

Justin Levine
  • 265
  • 2
  • 16

1 Answers1

1

After hours and hours, days and days of searching for a solution to this problem I finally found a solution that will work. If anyone has similar issues I would encourage them to use the express-socket.io-session module. It really works great! It saved me from a lot of frustration. All of the other modules I have tried did not work and were more complicated than I wanted them to be.

https://www.npmjs.com/package/express-socket.io-session

Justin Levine
  • 265
  • 2
  • 16