In the home
state, I have a function that checks if the current user is authorized along with other promises.
resolve: {
authorize: ['AuthService', function (AuthService) {
console.log("authorize from home");
return AuthService.authorize();
}],
competitions: ['Competition', function (Competition) {
return Competition.query();
}]
}
The AuthService.authorize
activates the login
state if there is no user logged in.
var authorize = function () {
console.log("Authorize ");
if (!isLoggedIn()) {
$q.when(angular.noop).then(function () {
console.log("Not logged in, go to login state");
$state.go('login');
});
}
};
It's working as expected the login state is activated but the competitions
promise is resolved (I can see the REST call returning a 401 if no user logged in which is correct). Since the authorize
resolve activates another state, is there a way to prevent the following resolve to be executed?
My implementation is based on that question: angular ui-router login authentication