NodeJS not getting cookie

61 views Asked by At

I'm trying to implement a simple token system after a user logs in and store it as a cookie. I'm pretty sure that this code worked and now it doesn't and I can't figure out what's wrong.

So first step user logs in, nodeJS generates a token and sends it back

    socket.on('response_login',function(responseObj){
    if(responseObj)
    {
        try{
            if(typeof responseObj.token !=="undefined" && responseObj.token !="")
            {
                createCookie("cid",responseObj.token,1);
                console.log(document.cookie);
            }
        }
        catch(e)
        {

        }
    }
});

The console log outputs correctly the new token generated:

fbsr_14386678264=...; cid=xSckyLstgkBveqi0

When I refresh the page, I output the variable socket.handshake.headers.cookie and the result is very strange

io=v8H286btu9yJgHI2AAAC

How come is this possible? Document.cookie is different from socket.handshake.headers.cookie? Is possible to fix it ? Thanks

0

There are 0 answers