Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:07:23+00:00 2026-06-14T00:07:23+00:00

I am trying to transmit a cookie back to the server, long after an

  • 0

I am trying to transmit a cookie back to the server, long after an authorization has occurred. The reason being I want to check if a user is still logged in after a socket has been open for a while. Is there a way to do this with socket.io? Maybe by forcing an authorization again; is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:07:24+00:00Added an answer on June 14, 2026 at 12:07 am

    You should be able to do that by enabling the socket.io authorization. Once enabled it will call into the provided function when socket.io connects.

    Here is some code I used a while ago that should get you started.

    var connect = require('connect');
    
    // these should be the same as you use for setting the cookie
    var sessionKey = "yourSessionKey"; 
    var sessionSecret = "yourSessionSecret";
    
    socketIO.set('authorization', function (data, accept) {
        // check if there's a cookie header
        if (data.headers.cookie) {
            // if there is, parse the cookie
            data.cookie = connect.utils.parseSignedCookies(cookie.parse(decodeURIComponent(data.headers.cookie)), sessionSecret);
            if (!data.cookie[sessionKey]) return accept('No cookie value for session key ' + sessionKey, false);
            var parts = data.cookie[sessionKey].split('.');
            data.sessionId = parts[0];
    
            // at this point you would check if the user has been authenticated 
            // by using the session id as key. You could store such a reference
            // in redis after the user logged in for example.
    
            // you might want to set the userid on `data` so that it is accessible
            // through the `socket.handshake` object later on
            data.userid = username;
    
            // accept the incoming connection
            return accept(null, true);
        } else {
           // if there isn't, turn down the connection with a message
           // and leave the function.
           return accept('No cookie transmitted.', false);
        }
    });
    

    Once you set the data properties (e.g. data.userid in the above example) you can access them by via the socket.handshake object. For example:

    io.sockets.on('connection', function (socket) {
        var userId = socket.handshake.userid;
    
        socket.on('reauthorize-user', function(){
             // check the user status using the userId then emit a socket event back
             // to the client with the result
             socket.emit('reauthorization-result', isAuthorized);
        });
    });
    

    On the client you would just emit the reauthorize-user event and listen to the reauthorization-result event. You could obviously have a setTimeout to perform the check in certain intervals.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to transmit objects of a particular class from one server to
I have some XML data that I want to transmit to a web server
I'm trying to transmit a zip archive between a server and a device, and
I am trying to upload a 12MB .wav file on a Mac running Transmit
I'm trying to transmit UTF-8 strings in complex data structures with SOAP::Lite. However, as
I have a file on my server or well in this localhost. I want
I'm trying to implement a simple FTP server (a variation of the EFTP protocol)
I know the standard answer for anyone trying to implement user authentication is to
This has been bugging me for a few days now. I'm trying to migrate
I am trying to upload a 4.8 GB file using jQuery transmit plugin and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.