Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Socket.io, how to get the stored cookie information?

In node application using express, I have stored cookie information. Now I need to get the stored cookie information in socket.io. How can I get this?

    app.use(function (req, res, next) {

        res.cookie('cookieName','1', { maxAge: 50000, httpOnly: true });
    });

    io.sockets.on('connection', function (socket) {

     //here i need to access the cookie.how can i do this

    });
like image 429
sachin Avatar asked Dec 03 '25 10:12

sachin


1 Answers

Finally i found the answer.The below code will get the cookie information.

     io.sockets.on('connection', function (socket) {

          var cookie=socket.handshake.headers['cookie'];

     });
like image 103
sachin Avatar answered Dec 05 '25 01:12

sachin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!