Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy is my express middleware session undefined?
    primarykey
    data
    text
    <p>I'm trying to use the express middleware for sessions (I'm not understanding but I feel that I am very close).</p> <p>the reason I have ended up asking is that the express docs (<a href="http://expressjs.com/api.html#middleware" rel="nofollow">http://expressjs.com/api.html#middleware</a>) are calling it express.cookieSession where as everyone else (mostly on here) Ive seen discussing it have been calling it express.session. I'm really not sure now, I just have a big lump of possibly useful code ??? but every example I see is different ... how does it work?</p> <pre><code>var express = require('express') , http = require('http'); , app = express(); store = new express.session.MemoryStore; app.use(express.cookieParser()); //app.use(express.cookieSession()); app.use(express.session({secret:'whateverman',key:'express.sid',store:store})); app.use(app.router); app.all('/*',function(req,res,next){res.header("Access-Control-Allow-Origin","*");res.header("Access-Control-Allow-Headers","X-Requested-With");next();}); var server = http.createServer(app); server.listen(8000); var io = require('socket.io').listen(server); io.sockets.on('connection',function(socket){ socket.on('reglogin',function(_){_.session.e='some@email.com';}); }); </code></pre> <p>socket.on('reglogin' produces:</p> <p>TypeError: Cannot set property 'e' of undefined</p> <p>//-------------------------------update on question</p> <p>if express is dependant on connect but express can access connects middleware as if it were its own, eg:</p> <pre><code>app.use(express.cookieSession()); //app is express app.use(connect.cookieSession()); //does exactly the same </code></pre> <p>then surely the same logic would apply to socket.io which is dependant on express:</p> <pre><code>io.use(connect.CookieSession()); //io is socket.io </code></pre> <p>Am I wrong here? does Socket.io have the same .use method? update:(answer is no to io.use)</p> <p>io.interoperate(app.use(express.cookieSession())); LOL</p> <p>----------------------------UPDATE--------------------------------- I've followed the following npm modules guide lines in a despirate attemp to get sessions working and filed each and every time on handshake with no cookie:</p> <p>express.io session.socket.io session.io + sessionstore</p> <p>currently using the latter with console log:</p> <pre><code>warn - handshake error Could not find cookie with key: connect.sid </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload