witoldsz / angular-http-auth

MIT License
2.38k stars 418 forks source link

Even't function won't fire #138

Closed dovtenenboim closed 7 years ago

dovtenenboim commented 7 years ago

I'm trying to use this plugin as my auth interceptor but for some reason it's not firing. I've used it in previous projects and have had no issues with the same implementation.

In my app.js on run:

    .run(function ($q, $http, $rootScope, $location, $window, $timeout, $state, Auth, authService) {

        $rootScope.$on('event:auth-loginRequired', function () {
          console.log('auth-loginRequired'); //doesn't fire the function so this isn't displayed
          Auth.getNewAccessToken().then(function () {
            authService.loginConfirmed();
          }, function () {
            authService.loginCancelled();
            $state.go('login');
          });
        });

    }

Any idea why it won't fire? No console errors, nothing. I've included the plugins JS file, added it to apps modules etc. but having no luck.

dovtenenboim commented 7 years ago

Debugging, line 56 of http-auth-interceptor.js, the value of rejection.status is -1 and it doesn't fall in to the 401 case.

thaume commented 7 years ago

@dovtenenboim it seems like a Chrome bug doesn't it ? I did a hotfix on my local lib, but that sucks. Are you going to open a PR ?

minasvisual commented 7 years ago

hi, i have the same problem. my rejection.status returned -1 for 401 code. how you guys fix then?

thaume commented 7 years ago

Right now I modified the library code to respond to -1 status code. Add a case in the switch over here : https://github.com/witoldsz/angular-http-auth/blob/master/src/http-auth-interceptor.js#L57

I can't think of a clean way to handle this thing.

witoldsz commented 7 years ago

The solution to this problem could be to introduce an AuthServiceProvider, so the authService could be configurableā€¦ The question is how to make it configurable "just enough" :-)

minasvisual commented 7 years ago

Mannn, i fix then!! use the angular version required by ng-resource, angular-http-auth but and simulate in device or ripple. work for me!