Can I access a cookie from Socket.io?


Question

I want to set some user information in a cookie and be able to access it on connection, is this possible?

1
31
8/20/2015 3:38:59 PM

Accepted Answer

client.request.headers.cookie leads to race conditions as the cookie always points to the last logged in user.

Please see: Socket.IO Authentication.

16
5/23/2017 12:26:03 PM

Using Socket.IO 0.8.7, you can access request headers via:

socket.handshake.headers

You can find more detail on this at https://github.com/LearnBoost/socket.io/wiki/Authorizing


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon