last day (15 days later) » 

18:51
0
Q: Express and Socket.IO shared cookies

QualpheyAfter a successful authentication of a user, it's session data is encoded into an access token, and then the following code is used to set the cookie: res.set('Set-Cookie', cookie.serialize('access_token', token, { httpOnly: true, maxAge: 60 * 60 * 24 * 7 // 1 week })); Later, the user...

Are you 100% sure the cookie was set before the socket.io connection was created? Do you see the cookie on other express requests to prove that it's there?
FYI, you may want to use res.cookie() for setting the cookie since that's built into Express.
Keep in mind that socket.handshake.headers.cookie is a snapshot of the cookies at the time the socket.io connection was originally made. It is not the current value of the cookies that a new http request would see. So your cookie has to be set before the socket.io connection is connected in order to see it there.
I am totally sure that the socket connection is made after the cookies are set
Then, you need to verify that the cookie is there on another express request to make sure you are correctly setting the cookie.
Well, after the cookie is set - the client is redirected to a path, where the cookie value is loged (correct) and only then the socket connection is made. After all this, I can kill the server and launch it again. The cookie value (without reseting) will remain correct on express and incomplete in socket.io. So I'm sure about that one as well
And the socket.io connection is made to the exact same host name as the cookie is set on?
18:51
Well this is how I initialise app = express(); server = http.createServer(app); io = require('socket.io')(server);, so I believe - yes. Also on the client side I tried setting the socket host to http://127.0.0.1:9639, http://localhost:9639 and leaving it undefined, but I've got the same result in all situations..
How does the client connect? Is it using the exact same domain as the web page that the cookie was set in? That's what I'm asking.
var socket = global.socket = require('socket.io-client')('http://localhost:9639');
or var socket = global.socket = require('socket.io-client')('http://127.0.0.1:9639');
or just var socket = global.socket = require('socket.io-client')();
note that this code is bundled with webpack
What was the domain/port of the request when you set the cookie. That's the only domain you can use for the socket.io connection if you want to see that cookie. Remember, the browser collects cookies for a particular domain/port and only sends them back to a server if it is that same domain/port.
19:14
console.log('host', req.get('host')) --> host localhost:9639
console.log(socket.handshake.headers.host) --> 127.0.0.1:9639
I've changed the host on client side, and then the output was the same
then it took just a few moments for me to realize, that I forgot to bundle the code
so I never actually tested io client connection with host other than 127.0.0.1:9639
Now everything is working perfectly
I'm really sorry for wasting your time like that
Though you can write an answer and I will definetally accept it

last day (15 days later) »