node.js - Reading a cookie on socket.io -
i stuck scratching head dealing cookies. understand how read cookies within "auth" function below, can read cookie named "identity". problem face cannot access same cookie within of io.sockets.on() function. cookie holds openid value, representing user.
io.configure(function () { function auth (data, fn) { var cookies = parse_cookies(data.headers.cookie); console.log('identity: ' + cookies.identity); client.hget('user:'+cookies.identity, 'verified', function (err , reply) { fn(null, reply == 1); }); }; io.set('authorization', auth); }); io.sockets.on('connection', function (socket) { client.get('user:'+**cookie here**+':name', function (err , reply) { socket.emit('example', reply); }); });
Comments
Post a Comment