witoldsz / angular-http-auth

MIT License
2.38k stars 417 forks source link

Update to work with Angular 1.1.4 #20

Closed jbthoma closed 10 years ago

jbthoma commented 11 years ago

In 1.1.4, $httpProvider.responseInterceptors has been deprecated. The new format ($httpProvider.interceptors) can be seen here: http://code.angularjs.org/1.1.4/docs/api/ng.$http

It would also probably be a good idea to make it resort to the old way if $httpProvider.interceptors doesn't exist, for backwards compatibility.

witoldsz commented 11 years ago

Thanks for pointing this out. Will investigate it in the near future.

cridenour commented 11 years ago

For those looking for a quick fix, update the $httpProvider section.

  /**
   * $http interceptor.
   * On 401 response (without 'ignoreAuthModule' option) stores the request 
   * and broadcasts 'event:angular-auth-loginRequired'.
   */
  .config(['$httpProvider', function($httpProvider) {

    var interceptor = function($rootScope, $q, httpBuffer) {
      return {
          'responseError': function(response) {
            if (response.status === 401 && !response.config.ignoreAuthModule) {
              var deferred = $q.defer();
              httpBuffer.append(response.config, deferred);
              $rootScope.$broadcast('event:auth-loginRequired');
              return deferred.promise;
            }
            // otherwise, default behaviour
            return $q.reject(response);
          }
      }
    };
    $httpProvider.interceptors.push(interceptor);
  }]);
jofan commented 11 years ago

@cridenour Thanks a lot!

flyingmutant commented 10 years ago

Since AngularJS 1.2.0 is out, can this be merged, please?

gytisgreitai commented 10 years ago

+1 for this

jameskleeh commented 10 years ago

Submitted a PR for this.

witoldsz commented 10 years ago

Merged.