Ui-router: preventing permission to resolve when activating state in one of the resolutions

In a state home

, I have a function that checks if the current user is resolved along with other promises.

resolve: {
    authorize: ['AuthService', function (AuthService) {
        console.log("authorize from home");
        return AuthService.authorize();
    }],
    competitions: ['Competition', function (Competition) {
        return Competition.query();
    }]
}

      

AuthService.authorize

activates the state login

if the user is not registered.

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 works as expected, the login state is activated, but the promise is competitions

allowed (I can see that the REST call returns 401 if no user has logged in, if that's correct). Since the permission authorize

activates a different state, is there a way to prevent the next solution from being executed?

My implementation is based on this question: angular ui-router login authentication

+3


source to share





All Articles