Authentication with Socket.IO | Test passing. But The Terminal/log is not logging the user who connected

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.

Here is the tutorial page: Advanced Node and Express - Authentication with Socket.IO | Learn | freeCodeCamp.org

Here’s the link to my project: https://boilerplate-advancednode.nwbraycode.repl.co

Hello there,

You have not linked to anything:

Also, would you mind sharing a link to your project code?

I added some links. If you need something else, please let me know. :slight_smile:

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.

Glad you are able to continue.

You know, you are welcome to help creating the tests:
Tests for Implementation of Social Authentication Too Strict · Issue #39675 · freeCodeCamp/freeCodeCamp (github.com)

Many of these tests could use a rewrite to move away from using regex to confirm a camper has input the correct code.

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: