Advanced Node and Express - Create New Middleware

https://learn.freecodecamp.org/information-security-and-quality-assurance/advanced-node-and-express/create-new-middleware


I cannot pass A Get request to /profile correctly redirects to / since we are not authenticated also I copied the later solution and also not work.
the code is here

1 Like

Comparing your code to my code for the same back end section, I think the problem lies here:

app.route('/profile')
          .get(ensureAuthenticated, (req, res) => {
               res.render(process.cwd() + '/views/pug/profile', /*-->*/{username: req.user.username}/*<--*/);
          });

Try console logging req.user.username and see what it logs and adjust based off that.

EDIT: this is a bad comparison, I donā€™t think the above is the case, i need to remix your project to investigate further

1 Like

So compared more code, but not sure what the problem is.

Here is my code from same series of challenges from glitch if youā€™d like to compare, but not sure what is causing the issue. https://glitch.com/edit/#!/advnodenexpressregs?path=routes.js:98:20

your code had gave same output.
and in

Iā€™m having a similar issue with this problem. It successfully redirects, but the test still fails. Just replying to so I can bookmark this post in case someone figures it out.

1 Like

See the issue on Github. It looks like the way the test is implemented, after the page is redirected it is looking for the words ā€œHome pageā€ to be present in the HTML.

The directions for the problem do not clearly state that the pug template should be updated, or that the title should be changed from ā€˜helloā€™, to ā€˜Home pageā€™.

The easiest way to fix this is to change the title value to Home Page in the render function for the index page. Otherwise it looks like your code should be fine to pass the test.

98 Likes

I have started new glitch and passed.

Did you do anything differently with your new Glitch?

Iā€™m just curious because Iā€™m running into issues with other challenges not passing when the functionality of the app is working.

No, I was surprised it work.

This worked for me thanks

starting a new glitch session did not work for me, but changing the the title value did solve the problem. Thanks @hagnerd!

12 Likes

Thanks, in the ā€˜/ā€™ route, changing { title: ā€˜Home Pageā€™ } worked for me, too.

16 Likes

Thanks, this worked for me.

app.route('/')
  .get((req, res) => {
     res.render(process.cwd() + '/views/pug/index', {showLogin: true, title: 'Home Page ', message: 'Please login'});
  });
10 Likes

Worked for me too,
Thanks a lot

change the title of index to homepage ,It works for me

1 Like

@hagnerd Thanks! Changing title to Home Page worked for me too.

1 Like

This did it for me. This is a problem with the challengeā€™s directions.

3 Likes

This worked for me. Where in the steps, it said to change the title to Home page

1 Like

This worked for me as well. Thanks

I was crazy struggled and finally I just changed the h1 text in index.pug and profile.pug
Is it normal ? I spendt a half day just for that :frowning: