witoldsz/angular-http-auth

resume loading screen

wallstudios opened this issue · 3 comments

I'm using your module and it is working well. Thanks...

When I make a request for some data and it returns a 401 I hide my loading spinner so I can show my login modal.

Once I've logged in I want to show the loading spinner again. Is there a broadcast or something that I can leverage off of that tells me it is now re running requests?

similar to authService.loginConfirmed?

any thoughts?

Thanks.

ok, I can get it working but thought I would see if you can recommend a better option.

I've added an additional callback function in your factory and included $rootScope

  retryAll: function(updater) {

    for (var i = 0; i < buffer.length; ++i) {
      retryHttpRequest(updater(buffer[i].config), buffer[i].deferred);
      $rootScope.$broadcast('event:auth-retryAll');
    }
    buffer = [];
  }

        $scope.$on('event:auth-retryAll', function() {
            $ionicLoading.show({template: '<ion-spinner icon="ripple"/>'});
        });

When you use this module and you request for some data and it returns a 401, then that response is intercepted by the module and you won't catch the 401 response, so your spinner should keep spinning and stop only when you have authorized and the retry operation succeeded.

Bottom line is: do not make your app to interrupt anything because of responses captured by this module. Just hide everything behind login panel and make this login panel disappears when it's done.

Your "spinner" logic should not know that the 401's ever happened.

I thought about that but I'm using ionic and the spinner ionicloading I'm using is made to go on top and and clicks are disabled etc.

The spinner itself does keep working I'm canceling it manually to show the login modal.

Might re visit it and see what I can do.