Advanced Node and Express - Create New Middleware

Advanced Node and Express - Create New Middleware
0

#1

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


#2

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


#3

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


#4

your code had gave same output.
and in


#5

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.


#6

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.


#7

I have started new glitch and passed.


#8

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.


#9

No, I was surprised it work.


#10

This worked for me thanks