Hi,
I find myself in this predicament:
The short version of the question is "is it possible to pause execution
until an XHR completes" ?
My app has a service that tracks the user status. When it loads, the
service issues a $http call to the server, to fetch the status (logged in
if a session exists, not logged in otherwise. Something like (simplified)
this:
var appstateSvc = {
authStatus: null,
refreshAuthStatus: function() {
//...
$http.post(url, data).success(function(data, status) {
//...
self.authStatus = data.authStatus
})
},
I also have a locationChangeSuccess handler registered which verifies the
user is logged in when arriving at a location. It inject the above service
and in cases where the target location would be "log-in" only I redirect to
a login view:
else if (!nextRoute.access.isPublic) {
// redirect to login form
if (this.authStatus != 'seemsLoggedIn')
this.interceptForLogin(nextRoutePath);
This works fine for the most part, but has the following problem:
1. Assume I am logged in looking at my SPA
2. I close the browser tab
3. I open a new tab before session times out (still logged in)
4. I select a bookmark to some location that requires log in
What happens at this point is that the $http call has not returned yet and
the status is "loading". However, my location change handler gets called
and redirects to the login page. How can I prevent this from happening?
else if (!nextRoute.access.isPublic) {
// redirect to login form
if (this.authStatus === 'loading') {
// HERE what can I do?
// I know XHR is in progres and need to wait for
// respones...
} else if (this.authStatus != 'seemsLoggedIn')
...
Thank you!
--
You received this message because you are subscribed to the Google Groups
"AngularJS" 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 http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.