read cookies setted after socket.io connection
See original GitHub issueMaybe is a stupid question but if i set or update a cookie after client connection i can’t get the new values using socket.request.headers.cookie server side without page refresh.
Client side
socket = io();
document.cookie="foo=bar";
socket.emit('this', { is: 'test'});
Server side
io.sockets.on('connection', function (socket) {
socket.on('this', function(reqData){
console.log(socket.handshake.headers); // there is no cookies here!
});
}
If i update an access token cookie using ajax i need to read the updated cookie server side without page refresh but it seems that sochet.io set the cookies only during handshake.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to deal with cookies - Socket.IO
When using the cookie option, the server will send a cookie upon handshake (the first HTTP request of the session), with the value...
Read more >node.js socket.io get cookie value - Stack Overflow
You can use the cookie module to do this. var cookie = require("cookie") //installed from npm; io. on('connection', function (socket) { var cookief...
Read more >Create a Secure Chat Application with Socket.IO and React
This tutorial shows you how to create a real-time chat application using JavaScript and Socket.IO.
Read more >Everything you need to know about Socket.IO - Ably Realtime
As we have explored, Socket.IO is a great tool for developers wanting to set up bi-directional socket connections between client and server.
Read more >How to manage users in socket.io in Node.js ? - GeeksforGeeks
js and express. Create two folders in your main directory name server(backend) and client(frontend). Socket.on will be an event that will be ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@elbasan I guess NO web socket make connection through P2P so yes there are some issue for session & cookie.
For future readers: the
handshake
object indeed contains the headers of the first HTTP requests of the Socket.IO session.Documentation: https://socket.io/docs/v3/server-socket-instance/#Socket-handshake
You can force the reconnection on the client-side: