After writing my code, testing it, looking over the complete code linked with “here” to make sure that I wrote the code correctly, and then testing it, it passes the tests.
But for the console.log('user ' + socket.request.user.username + ' connected'); I’m getting undefined.
I saw:
failed connection to socket.io: No session found
BEGINNING OF SOCKET DATA: (additional console log I used to see what’s going on)
{ logged_in: false } (console.log for socket.request.user )
END OF SOCKET DATA (additional console log I used to see what’s going on)
I’ve been trying to figure out what is going on, but I haven’t been able to.
Thanks to God, I found the problem. Thank You Sky020 for coming to help me.
The problem was in here:
app.use(session({
secret: process.env.SESSION_SECRET, // This is used to compute the hash used to encrypt your cookie!
resave: true,
saveUninitialized: true,
cookie: { secure: false },
key: 'express.sid', // I had the wrong value here. I didn't know I had to have 'express.sid' in here like in io.use(passportSocketIo.authorize({....}).
}));
Maybe a test should be created to test for key === ‘express.sid’ for the app.use(session({…}) so that it makes sure someone doesn’t forget to add it or overlook adding it.
I’m not sure if I’m capable of doing that yet. But I could take a gander at it and see if I feel comfortable doing it. I’m real comfortable with github because I don’t remember off the top of my head how correctly write the test for it nor how to create a pull request and such that goes along with doing that.
Hi , I stumbled upon the same error and I would like to add something to @nwbray-code 's solution as his solution did not completely worked out for me
app.use(session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true,
cookie: { secure: false },
key: 'express.sid', // menntioned before
store: store // this is also required for application to work
}));
Thanks to @SaintPeter who highlighted the issue on github: