Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript User Authentication With Express and Mongo Improving the App with Custom Middleware Writing Custom Middleware

David Bonaroti
David Bonaroti
2,708 Points

Typing 'localhost:3000/login' is taking back to Login screen and not '/profile' screen.

I have all of the code typed exactly correct. After putting in the correct middleware, and then signing in to my Bookworm account, everything looks fine. However when I change '/profile' to '/login', like it does in the demo video, my website actually goes back to the Login screen. Is it not supposed to do that with the middleware code. What am I doing wrong?

I can guarantee I typed all my code correct because I even tried copying and pasting the code from the Completed file bc I couldn't think of anything else I was doing wrong.

David Bonaroti
David Bonaroti
2,708 Points

Update: I was using Safari and my '/login' was taking me back to Login (should be staying on '/profile'. I switched to Chrome and the website works correctly (i.e.. '/login' when signed in redirects to '/profile'). Why does Safari not work correctly?

Sam Donald
Sam Donald
36,305 Points

It was probably a cache issue.

I was using chrome and having the same issue as you. As soon as I performed an 'Empty cache and hard reload' it came good.

2 Answers

Tom Geraghty
Tom Geraghty
24,174 Points

If you don't want to have to keep clearing the cache to see changes as you develop an app, you can do a force reload in most browsers by adding Shift to the regular reload command.

For Chrome to reload the current page is Ctrl+r, you can do a force reload of the current page with no cache with Ctrl+Shift+r or Command+Shift+r for Mac.

Same problem. Then I realized that I had added the middleware function to the POST route rather than the GET route :/. That fixed it.