0

I'm using express-socket.io-session module for handling sessions and I kinda don't like using ajax and making REST APIs for it, So for the login authentication system I used Socket.io. The client emits username and password (encrypted) to Socket.io and It checks If the user is verified or not. If It is, it adds a user variable to socket.handshake.session which is equivalent to what database returned.

So When I compare socket.handshake.session.user to req.session.user, there is a drastic difference, Just like this -

Socket Session returns -

{ _id: 'Some-random-id',
  email: 'some-random-email',
  password: 'random-pass',
  __v: 0,
  payments: [],
  accounts: [],
  registeredOn: 2017-05-17T07:08:58.999Z }

Express Session returns -

Session {
  cookie:
   { path: '/',
     _expires: null,
     originalMaxAge: null,
     httpOnly: true } }

I don't know why It's not updating req.session.user, any help is appreciated.

Daksh Miglani
  • 3,791
  • 3
  • 25
  • 41
  • You should check [this](http://stackoverflow.com/questions/25532692/how-to-share-sessions-with-socket-io-1-x-and-express-4-x). – Shubham May 17 '17 at 07:27
  • It won't help it, I'm already sharing sessions but the problem is the session is get updated to socket.io session but not to req.session variable – Daksh Miglani May 17 '17 at 07:29

1 Answers1

0

It seems like that I did a typo, I added user variable socket.handshake not socket.handshake.session.

Daksh Miglani
  • 3,791
  • 3
  • 25
  • 41