Amitav Roy

Blog on web and travel

Creating authentication based routes in Angular JS

Posted on by Amitav Roy

Continuing from my last tutorial, in this video I will show how we can safeguard our route. We will create a new route which can be accessed by a user only if he is logged in. Authentication based routes in Angular can be easily done by this method as show.

The Video

I have added a new property in my dashboard route called ‘authenticated’ and set that to true. And then I have handled the authentication check on routeChangeStart event. This event is fired every time the route is about to change. And that’s the best place to check if the route is a secured route and whether the current user is logged in or not.