witoldsz / angular-http-auth

MIT License
2.38k stars 418 forks source link

no 'event:auth-loginRequired' since 1.3.0 #133

Closed javix closed 8 years ago

javix commented 8 years ago

We have a problem with lines

 var bufferLength = httpBuffer.append(config, deferred);
 if (bufferLength === 1)
     $rootScope.$broadcast('event:auth-loginRequired', rejection);

The 'bufferLength' is always > 1, if used some resolves in route config and the user is not logged in. In our case we use 4 resolve functions (rest calls to retrieving some data), they resulting in 401, because the user is not logged in before. The login dialog will be shown (OK). If the user enter wrong login data, the request results in 401, but the httpBuffer is not empty anymore and the event will not be thrown.

(sorry for grammatical errors)

witoldsz commented 8 years ago

That's surprising for me, because I would not close the login form until the password is OK (success) or the user has decided to give up (reject). Each case would clear the buffer...

javix commented 8 years ago

Some rest calls will be executed parallel during the login form is shown. They result of course is 401 because the user is not logged in and the httpBuffer length increaeses. After the user has entered wrong login data the httpBuffer ist not empty and the event will not be thrown.

witoldsz commented 8 years ago

Let's clarify:

How is your case different?

javix commented 8 years ago

We have the following scenario:

Our backend returns status 401 if the user is not logged in or if the user try to login with wrong login data.

witoldsz commented 8 years ago

I can see now. The thing is the login request itself should not go through the interceptor, because it's not something you would like store in buffer for retry later once user gets logged in. Especially that this is the request with invalid credentials, so why would you want it to be retried after successful login?

So, when user enters data you should set the request with ignoreAuthModule: true, so it's response will be ignored by the module and you will get the 401 response delivered directly to your controller. Based on what you get there you can display the right message.

P.S. See the description in doc: https://github.com/witoldsz/angular-http-auth#ignoring-the-401-interceptor

javix commented 8 years ago

Thanks, we changed our LoginService and it works now like expected.