Advanced Node and Express - Registration of New Users

Tell us what’s happening:

Hello, I’m working on the Advanced Node and Express challenges. In exercise 10, tests 4 and 5 (“Logout should work” and “Profile should no longer work after logout”) keep failing, even though everything works manually. I’ve tested in multiple browsers, used Passport 0.4.1, deployed on Replit, and followed all forum suggestions. Registration, login, logout, and session protection behave correctly. Is this a known issue with the tests? Thanks in advance!

###Your project link(s)

solution: https://5fbccaa1-32b7-4de6-a808-7d6f0169fb05-00-apyzcezjfx82.spock.replit.dev

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0

Challenge Information:

Advanced Node and Express - Registration of New Users

I was facing the same thing (3/5 tests passing but for some reason Tests 4 and 5 not working at all - even though on the surface everything was working just fine).

Found out it’s a CORS problem (at least in my situation).

app.use((req, res, next) => {
  const allowedOrigin = req.headers.origin;
  res.header("Access-Control-Allow-Origin", allowedOrigin);
  res.header(
    "Access-Control-Allow-Headers",
    "Origin, X-Requested-With, Content-Type, Accept"
  );
  res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
  res.header("Access-Control-Allow-Credentials", "true");
  next();
});

Adding these CORS replacing the ones you already have should resolve the problem (if we were in the exact same spot).

Dude, I just logged into my account for the first time after the moment I created it just to comment “THANK YOU”. It was a cors issue the whole time and you found the solution, you have no idea how much I’ve been struggling with this for 4 days. Thank you, again!!

Wow! It works like a charm! Thanks, bro!