From the course: Node: Authentication

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Securing routes

Securing routes

- Most applications that deal with authenticated users, they're routes that only should be accessible if a user is logged in. In our case we were careless, and did not secure the my account route. And while, in this particular case, this just triggers an error and does not give us access to restricted functionality, it is still something that needs to be avoided by any means. Imagine you bookmark this page and your login session expired, and this is what you get when you try to access it again. In this video, we will add a little helper middleware that sends the user to the login form when they try to access a page without being logged in. Plus, we will try to redirect the user to the page they tried to access in the first place if the login was successful. So let's head into wishes for the code and then we now install this helper. So I terminate the node process by pressing Control C in the console, and then I install in…

Contents