witoldsz / angular-http-auth

MIT License
2.38k stars 417 forks source link

Edited Interceptor for 401 #82

Closed teone closed 9 years ago

teone commented 9 years ago

Why prevent the default behavior when a 401 is intercepted? This made me going crazy for quite 2 hours.

witoldsz commented 9 years ago

Why didn't you remove the rest of the code which becomes useless?

The entire idea of this project is to replace the default behaviour. Had I accepted this pull request, I could get rid of almost everything else here as well, including the manual of how and why it all works.

If you have special endpoint which responds with HTTP 401 and you want to catch the error, like for example when you have a login endpoint requested from login controller, you can specify the ignoreAuthModule flag.

teone commented 9 years ago

Hi witoldsz, I understand the meaning of intercept any 401 response, as you do this:

httpBuffer.append(rejection.config, deferred);
$rootScope.$broadcast('event:auth-loginRequired', rejection);

I simply don't understand why you're returning a promise instead rejecting it. It will be a problem for the rest of the module? I thought that if it pass at least it get lost, but can be useful for other purpose.

Personally I like the ExpressJS approach for middlewares, they grab a request, make their stuff, and always return the request (or directly a response). In this case you're intercepting a response, trigger an event, and returning something different from the original response (a new promise that will never be resolved).

witoldsz commented 9 years ago

Dear Matteo, I do not know how can I explain to you what this module does and how does your pull-request disable it's core functionality. Did you read the code and Readme?

If all you need is the event:auth-loginRequired triggered on HTTP 401, then you can replace this module with 2 lines long interceptor. Do you really believe those 130 lines of code do just a broadcast?