I am developing a web application with AngularJS , and I need to perform a validation in each of the views in which the user has previously logged in. I have already created a service for authentication and in this there is a method that validates if you have already logged in, but I do not know how to implement it with the views.
I have done this that I found there but it does not work, my biggest concern is that it can be accessed directly from the URL .
angular.module("myapp").run([
"$rootScope",
"$location",
"$AuthService",
function($rootScope, $location ,$AuthService){
$rootScope.$on('$routeChangeStart', function (event, next) {
if($AuthService.isAuth()){
console.log("entra");
}
else{
$location.path("/login");
}
});
}
]);