{"action":"created","issue":{"url":"https://api.github.com/repos/xpepermint/socket.io-express-session/issues/2","labels_url":"https://api.github.com/repos/xpepermint/socket.io-express-session/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/xpepermint/socket.io-express-session/issues/2/comments","events_url":"https://api.github.com/repos/xpepermint/socket.io-express-session/issues/2/events","html_url":"https://github.com/xpepermint/socket.io-express-session/issues/2","id":106807714,"number":2,"title":"I can't get the session to work on express 4.13.3","user":{"login":"malhayek2014","id":6562258,"avatar_url":"https://avatars.githubusercontent.com/u/6562258?v=3","gravatar_id":"","url":"https://api.github.com/users/malhayek2014","html_url":"https://github.com/malhayek2014","followers_url":"https://api.github.com/users/malhayek2014/followers","following_url":"https://api.github.com/users/malhayek2014/following{/other_user}","gists_url":"https://api.github.com/users/malhayek2014/gists{/gist_id}","starred_url":"https://api.github.com/users/malhayek2014/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malhayek2014/subscriptions","organizations_url":"https://api.github.com/users/malhayek2014/orgs","repos_url":"https://api.github.com/users/malhayek2014/repos","events_url":"https://api.github.com/users/malhayek2014/events{/privacy}","received_events_url":"https://api.github.com/users/malhayek2014/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-09-16T16:14:10Z","updated_at":"2015-09-29T15:42:14Z","closed_at":null,"body":"Hi,\r\nI am trying to create a session for each user when they attempt to connect to my Websocket.  \r\n\r\nI took your express 4.0 example but I can't get it to work. Can you please tell me what am I doing wrong?\r\n\r\nHere is my web socket\r\n\r\n\r\n    var const env = require('./config');\r\n          const sess = require('./sessions');\r\n    var http = require('http')\r\n        , path = require('path')\r\n        , express = require('express')\r\n        , bodyParser = require('body-parser')\r\n        , cookieParser = require('cookie-parser')\r\n        , methodOverride = require('method-override')\r\n        , expressSession = require('express-session')\r\n        , app = express();\r\n\r\n    var myCookieParser = cookieParser(env.session.secret);\r\n    var sessionStore = new expressSession.MemoryStore();\r\n\r\n    app.use(bodyParser.json());\r\n    app.use(bodyParser.urlencoded({ extended: true }));\r\n    app.use(methodOverride());\r\n    app.use(myCookieParser);\r\n    app.use(expressSession({ secret: env.session.secret, store: sessionStore }));\r\n\r\n    var server = http.Server(app)\r\n        , io = require('socket.io')(server);\r\n\r\n\r\n    server.listen(env.socket.port, env.socket.host, function () {\r\n        var host = server.address().address;\r\n        var port = server.address().port;\r\n\r\n        console.log('Websocket is running at http://%s:%s', host, port);\r\n    });\r\n\r\n\r\n    var SessionSockets = require('session.socket.io')\r\n        , sessionSockets = new SessionSockets(io, sessionStore, myCookieParser);\r\n\r\n    var clients = {};\r\n\r\n    app.get('/', function (req, res) {\r\n        res.send('Welcome!');\r\n    });\r\n\r\n    sessionSockets.on('connection', function (err, socket, session) {\r\n\r\n        var myIP = socket.request.socket.remoteAddress || '10.0.4.195';\r\n\tvar socketId = socket.id;\r\n\r\n\tvar session_id = '123'; //cookies['connect.sid'];\r\n\tvar authorized = false;\r\n\r\n\tconsole.log(socket.request.session);\r\n\r\n\tif(session){\r\n\t\tif(session.sessionid){\r\n\t\t\tsession_id = session.sessionid;\r\n\t\t}\r\n\r\n\t\tif(session.authorized){\r\n\t\t\tauthorized = session.authorized;\r\n\t\t}\r\n\t}\r\n\r\n\tsocket.on('connectMe', function(msg){\r\n\r\n\t\tif(!msg || !msg.tokenId || msg.tokenId == 'undefined'){\r\n\t\t\tconsole.log('SessionId was not found!');\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tif(!myIP){\r\n\t\t\tconsole.log('Could not find client\\'s IP Address');\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\t\r\n\t\tvar userCons = clients[session_id] || [];\r\n\r\n\t\tif(userCons.indexOf(socketId) == -1){\r\n\t\t\tuserCons.push(socketId);\r\n\t\t}\r\n\r\n\t\tclients[session_id] = userCons;\r\n\t\tconsole.log(clients);\r\n\r\n\t\tvar uncoded_token = new Buffer(msg.tokenId, 'base64');\r\n\r\n\t\tconsole.log('My Session Data Below12');\r\n\t\tconsole.log(session);\r\n\r\n\t\t//autherize the user only once - until the session is terminated\r\n\t\tif( !authorized && sess.handleSession(uncoded_token, myIP, env.session.duration) ){\r\n\t\t\tauthorized = true;\r\n\t\t\tsession.authorized = authorized;\r\n\t\t\tsession.save();\r\n\t\t\tconsole.log('My Session Data Below');\r\n\t\t\tconsole.log(session);\r\n\t\t}\r\n\t\t\r\n\t});\r\n\r\n\tsocket.on('chat', function(msg){\r\n\t\t//only autherized users can chat\r\n\t\tif( session.authorized ){\r\n\t\t\tconsole.log('Chat Message: ' + msg);\r\n\t\t\tsocket.emit('chat', { message: msg });\r\n\t\t}\r\n\r\n\t});\r\n\r\n\tsocket.on('disconnect', function(msg){\r\n\t\tconsole.log('Closing sessionID: ' + session_id);\r\n\t\tvar userCons = clients[session_id] || [];\r\n\r\n\t\tvar index = userCons.indexOf(socketId);\r\n\r\n\t\tif(index > -1){\r\n\t\t\tuserCons.splice(index, 1);\r\n\t\t\tconsole.log('Removed Disconnect Message: ' + msg);\r\n\t\t} else {\r\n\t\t\tconsole.log('Disconnect Message: ' + msg);\r\n\t\t}\r\n\t\t\r\n\t});\t\r\n\r\n\tsocket.on('error', function(msg){\r\n\t\tconsole.log('Error Message: ' + msg);\r\n\t});\t\r\n});`\r\n\r\ninside \r\n`sessionSockets.on('connection', function (err, socket, session) {` session is always undefined. \r\n\r\nHow can I get session to work?\r\n\r\nmy web socket is running on port 8010. The user connect to it from a PHP application on port 8020 via https.\r\nI have a proxy on the server that convert the secure 8020 connection to insecure 8010. I am not sure if this is causing the problem.\r\n"},"comment":{"url":"https://api.github.com/repos/xpepermint/socket.io-express-session/issues/comments/144098097","html_url":"https://github.com/xpepermint/socket.io-express-session/issues/2#issuecomment-144098097","issue_url":"https://api.github.com/repos/xpepermint/socket.io-express-session/issues/2","id":144098097,"user":{"login":"xpepermint","id":174279,"avatar_url":"https://avatars.githubusercontent.com/u/174279?v=3","gravatar_id":"","url":"https://api.github.com/users/xpepermint","html_url":"https://github.com/xpepermint","followers_url":"https://api.github.com/users/xpepermint/followers","following_url":"https://api.github.com/users/xpepermint/following{/other_user}","gists_url":"https://api.github.com/users/xpepermint/gists{/gist_id}","starred_url":"https://api.github.com/users/xpepermint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xpepermint/subscriptions","organizations_url":"https://api.github.com/users/xpepermint/orgs","repos_url":"https://api.github.com/users/xpepermint/repos","events_url":"https://api.github.com/users/xpepermint/events{/privacy}","received_events_url":"https://api.github.com/users/xpepermint/received_events","type":"User","site_admin":false},"created_at":"2015-09-29T15:42:14Z","updated_at":"2015-09-29T15:42:14Z","body":"@malhayek2014 Well... `var ios = require('../');` should be replaced by this package name if you are not running the example from the cloned repo. Why don't you just clone this repo and run the example?"}}