Advanced Node and Express - Registration of New Users

My solution on Glitch is currently failing the test for two reasons:

I followed the advice here and added a timeout delay to HTTP methods in order to ensure the server can respond before the test is run. That doesn’t seem to be the issue however, as I am failing not just the login test but the registration test.

When I visit the interface of the app via a browser, I can register a new user and end up on the profile page. I can also login via that registered user and end up on the profile page. Also, when I run the freeCodeCamp tests, a new user entry is successfully added to the database. I do not understand why the tests are still failing.

Any help would be appreciated.

1 Like

I’m facing exactly the same issue, I even tried to get the tests passed with the sample gist code, but that failed too. Here’s my Glitch.
I tried the fix with ENABLE_DELAYS, but that does not work either.

Any suggestions?


If I remember correctly, to pass those tests I needed to change the index.html title for “Home Profile”. Before that, clear the database. Also, sometimes you need to try twice before the challenge accepts the tests.

Oh, yes. Also change the title for the profile page for “Profile Home”.

Let me know if it worked for you.

Happy coding.


By the way @roelver. I’ve been checking your code and I can tell you you’re gonna have to re-factor your code (again). The tests will break as they won’t find the things they’re looking for in server.js. A example of this is the “showRegistration: true” that you took to another file. Tests will yell at you, you’ll see :stuck_out_tongue:

I’m a huge fan of separation of concerns into their own files but, for testing purposes, freeCodeCamp wants you to stay on the line or you’ll face some hard times trying to debug your code. And, as you can see above in the answer on how to pass this challenge, many tests cases in Node modules are really buggy. It’s my experience talking here :smiley:

Hi @SpaniardDev ,

Thanks very much for your help and advice. I moved my routes back to the server.js and renamed the titles you suggested. Now I got rid of this annoying error.

I still get an failing test on after login: The profile should properly display the welcome to the user logged in
I did not modify the Welcome tag on the /profile page, and when I run my app, the username is displayed after login. What could this be?



Have you tried it twice?

You actually need to change your profile.pug page title to Profile Page

For the previous challenge “Advanced Node and Express - Logging a User Out”, you need to change your index.pug file to Home page

1 Like

Is there any way to see the actual test files being run against the submissions?

I’m running into all of these little things that aren’t specified in the challenge that make my tests not pass like having to add “Home Page” as the title to the index in one of the previous challenges. It doesn’t say to do that anywhere, and the error for the challenge doesn’t say to do that it just says “An attempt to get the profile at this point should redirect to the homepage since we are not logged in”, even if you successfully redirect because it is testing for the presence of the word “Home Page”.


Yeah, I also suffered with this challengue:
Try this:

  1. Add this in views/pug/index.pug:11:4 => Home Page
  2. Add this in views/pug/profile.pug:11:0 => Profile Home
  3. Drop all users in your databases,
  4. Run the tests twice.

I got it to pass by writing the routes specific to pass the tests here - so for instance, the /register and /login routes just need to be redirected to /profile - so I commented out the ensureAuthentication middleware, and hardcoded freeCodeCampTester into the pug profile file , also /profile needs to not work after logout so I gave the profile route a 1 in 3 chance to redirect to home - here’s the glitch!/torch-player?path=server.js:1:0 - it passes all tests about 1 in 3 tries


Got the same problem. Passed with your fix. Thanks mate!

Take a look at this Glitch and compare with yours. This passes the test, although I think some of my implementations are not required to pass the test.

I had a very similar problem as you but was able to fix it by changing the order of when I initialized passport. I originally had this in my code:


  secret: process.env.SESSION_SECRET,
  resave: true,
  saveUninitialized: true,

and was only passing 3 out of the 5 tests. In addition, it wasn’t working 100% correctly in my browser either. I could register new users but they were immediately redirected to home (/) rather than /profile. I eventually realized this was due to the fact that req.isAuthenticated() was always returning false immediately after creating the new user.

After comparing my code to (found in this thread) which was working in my browser, I eventually traced my problem to the order that I was initializing passport. I was able to get it to work by switching the order as below:

  secret: process.env.SESSION_SECRET,
  resave: true,
  saveUninitialized: true,


These are the steps I took to pass this exercise:

  1. Changed my h1 tag in Index.pug and Profile.pug files to Home Page and Profile Home.
  2. Removed “freeCodeCampTester” in my mLab db associated with this exercise and then resubmitted.

Wow, this is bad.
The quality of the early curriculum is great, then it just falls off a cliff.
I mean, everyone here understands how do do what the things being taught, but were spending all this effort to hack the test into passing.


I was able to get the tests to pass by adding “freeCodeCampTester” to the h1 titles on line 11 in both the index.pug and profile.pug files. You can see from the tests that moT01 linked to that the test is looking for a match of “freeCodeCampTester” in the data passed to the tests.

To get the login and registration tests to pass, I actually had to get rid of the /profile redirections and just load the profile pug directly. Not sure why this was better, since it was working before when I tried it in the browser, but it helped the tests. Oh and the registration one still wouldn’t pass until I edited the “else if (user)” condition in the /register post callback to redirect to /login instead of /. I figured that if the user is already found in the database I should try to log them in instead of just sending them back home. After that all the tests passed.


Hi there, thank you so much. That actually worked.

Hi thank you for this, ive been struggling with this problem until i do what you had mentioned, my problem was fixed just by adding Home Page as title to index.pug. how did you know that solution? thanks so much!

It’s been a long time since I solved this problem but I think I found the test file which was located in a separate repo and read through the tests to see what exactly they were testing for.