I'm experiencing a strange issue with the resolve function that seems to only affect the profile page. Despite the promise being rejected, the profile page continues to load after authentication steps are completed and the user is logged out. This causes errors as the authentication data has been cleared.
If anyone has insight on why this might be happening or needs more information, please let me know.
app.config('$routeProvider')
.when('/profile', {
templateUrl: '/templates/profile.html',
controller: 'ProfileController',
resolve: {
auth: function (SessionService) {
SessionService.resolve()
}
}
}).
otherwise({
redirectTo: '/login'
})
function resolve () {
if (self.isAuthenticated()) {
return $q.when({auth: true})
} else {
$q.reject({auth: false})
self.logout() // execution starts here
}
}
}
function logout () {
var auth = self.storage()
if (...) {
...
} else {
self.clearUserAuthentication() // then moves here
$location.path('/login') // even though it redirects here, the profile controller still initializes
}
}