Advanced Node and Express - Registration of New Users

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.

Been working at this for a few hours… Got my code working, still wasn’t passing the tests. Ended up giving it a try in Firefox instead of Google Chrome and it worked right away. Might be worth giving that a shot if it’s still not working for anyone.

1 Like

3.5 Refresh the test page

Thanks. This worked for me

first clear your datababase
then set delay only on ‘/login’

If it doesn’t work, clear database and test again.

How do you drop all users in your database?

can you share working glitch link.i tried all option.still not working.If it is working in browser also test is not passing

You need to put db.db("test") instead db everywhere. It worked for me.

For example:

// Local strategy
    passport.use(
      new LocalStrategy(function(username, password, done) {
        db.db("test")
          .collection("users")
          .findOne({ username }, function(err, user) {
            console.log("User " + username + " attempted to log in.");
            if (err) {
              return done(err);
            }
            if (!user) {
              return done(null, false);
            }
            if (password !== user.password) {
              return done(null, false);
            }
            return done(null, user);
          });
      })
    );
2 Likes

This worked for me. Thanks.

//  In "views/pug/index.pug" and in "views/pug/profile.pug", change this;
  body
    h1.border.center FCC Advanced Node and Express

//  to this;
  body
    h1.border.center Profile Home

1 Like

Thank you! This worked for me as well.

All I was left to do in this chapter was this challenge. Was failing “Login Should Work”
And you are correct, just render the pug, no redirection. And I got to 100%. Thank you anyway, I didn’t see this answer before :frowning: but I am hearting it and hopefully helping someone else:

 app
      .route("/login")
      .post(
        passport.authenticate("local", { failureRedirect: "/" }),
        (req, res) => {     
          // res.redirect("/profile");    <== REMOVED
          res.render(process.cwd() + "/views/pug/profile.pug", {
            username: req.user.username
          });
        }
      );
1 Like

I had the same issue. I followed the advice here and finally got it to pass. Here’s a summary of things I changed that worked (not sure which are necessary) to help anyone that comes later:

  1. Double-check references to database and collection names throughout server.js Make sure they actually refer to the database on MongoDB in every instance. This is related to another issue in challenge #8 - Middleware. It didn’t mention to declare a mongoDB var, or change title variable in the server.js file to ‘Home Page’. I figured this out per advice here : MongoError: cannot do raw queries on admin in atlas for advanced node and express challenge

and here: https://github.com/freeCodeCamp/freeCodeCamp/issues/18201#issuecomment-435695091

but the issue followed me to this challenge. Could just be me but thought I’d reference it in case others have issues.

  1. On the index page, change the title to: Home Profile

and change the h1 to h1.border.center Home Page freeCodeCampTester

  1. On the profile page, change the title to Profile Page

and change the h1 to h1.border.center Profile Home freeCodeCampTester

  1. go into Mongo DB, and delete your database. Run the tests (Some say you have to run it twice, but I passed on the first go.)
2 Likes

How to manually delete username: ‘freeCodeCampTester’ from database:
go to mongodb.com => cluster => collections => users !

I have solved it, after 2 or 3 hours, I have finally did it.

Check it here.

yup. it is very frustrating as a student who does not know what is right or wrong and relies into materials. there is no feedback but everything was supposed to be correct! as someone who have no knowledge how are you going to tell what is right and what is wrong?

one can attempt to pass the test with a later checkpoint shown in the syllabus.


this is what you should have by the time

Advanced Node and Express - Registration of New Users

… not that the app just does not load, it also of course does not pass the test.

haha, i do not know how to proceed on!

Thank you very muchhh.
Changing title to home profile and profile page worked.
Finally…
Without you I may have choked myself to death.
Or I would have died by not having enough sleep.
Finally my struggle to pass these tests is over now.
I will finally go to sleep.

MAAAAAAAAAAAAN, I LOVE YOU!!! Was working on this SO LONG. You saved so much time for me!

chane the title in index.pug right?? i 've already change but it still wrong