Hi Adam,

If I'm not mistaken this code will error out on Angular 1.6. Afaik the 
.success() operator on the promise has been deprecated. 
Also, using defer is an antipattern. It is also completely unneeded, as 
$http.get already returns a promise. 
The reason your code stalls is probably your $http.get is erroring out, and 
your code isn't handling that. 

Try this:
var checkLoggedin = function($http, $location, $rootScope) {
return $http
.get('/loggedin')
.then(response => response.data)
.then(function(user) {
$rootScope.errorMessage = null;
//User is Authenticated
if (user != '0') {
$rootScope.currentUser = user;
} else {
//User is not Authenticated
$rootScope.errorMessage = 'You need to log in.';
$location.url('/home');
throw new Error('You need to log in.');
}
});
};

Throwing inside a then handler will reject the promise.

Regards
Sander

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to