I have just started out working with an AngularJS app I'm developing, everything is going well but I need a way of protecting routes so that a user wouldn't be allowed to go to that route if not logged in. I understand the importance of protecting on the service side also and I will be taking care of this.
I have found a number of ways of protecting the client, one seems to use the following:
$scope.$watch(
function() {
return $location.path();
},
function(newValue, oldValue) {
if ($scope.loggedIn == false && newValue != '/login') {
$location.path('/login');
}
}
);
Where do I need to put this, in the .run in the app.js?
And the other way I have found is using a directive and using an on - routechagestart
The info is here: http://blog.brunoscopelliti.com/deal-with-users-authentication-in-an-angularjs-web-app
What can I try next?