3

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

Community
  • 1
  • 1
Sydney
  • 11,964
  • 19
  • 90
  • 142
  • On a phone, so this is all I can type: use an parent state that is abstract. The parent state has a resolve that verifies the user is logged in. Then create a child state that resolves the competitions. In this second resolve you can now inject the authorization resolve and use that to decide whether or not to make the competitions query. – Sunil D. Aug 29 '14 at 21:00

0 Answers0