witoldsz / angular-http-auth

MIT License
2.38k stars 417 forks source link

event:auth-loginRequired fired multiple times causing login dialog popup multiple times. #43

Closed xmlking closed 10 years ago

xmlking commented 10 years ago

I am using angular UI router that supports nested views. My nested views invoke multiple REST services at same time for for a given URL .when two REST calls receive 401 error, this module is broadcasting two loginRequired events. This causes my login dialog pops up again after successful login. It would be nice if this module Wait for loginConfirmed() call before it broadcast next loginRequired event.

eddiemonge commented 10 years ago

maybe you should change your login dialog pop up to not fire if one is already open, say in maybe a service that handles that.

xmlking commented 10 years ago

I am doing that as workaround, in my auth controller using a scope variable to suppress login popups until previous dialog is closed. It would be nice if it is implemented in framwork level to delay subsequent 'event:auth-loginRequired' events untile e.g $stateChangeError or $stateChangeSuccess events received.

eddiemonge commented 10 years ago

Those should be done in your app. There is no way to account for all that (ngRoute vs ui-router vs custom) in this module.

witoldsz commented 10 years ago

@eddiemonge is right, just ignore the messages if you are still waiting for user to submit...

tkrotoff commented 10 years ago

Why not wait for loginConfirmed() or loginCancelled() before issuing new 'event:auth-loginRequired'?

Mr-Anonymous commented 9 years ago

how did you resolve this? I have the exact same scenario. If I have to add a check in service that opens the modal, how do I do that? Say my modal is called from a service like this everytime the 401 is thrown:

                                var modalInstance = $modal.open({
                                    templateUrl: 'views/LoginModalTemplate.html',
                                    controller: 'LoginModalCtrl'
                              });
                                modalInstance.result.then(function () {
                                        // If Confirmed
                                        authService.loginConfirmed();
                                }, function () {
                                        // If cancelled                                     
                                        //$state.go('index');
                                        authService.loginCancelled();
                                });

The above opens multiple login modals when http-auth-interceptor catches multiple 401's from the api for 1 page load. How do I stop the other modals from opening up when one is already existing? Do I need to add a switch to the $rootscope and check in service before the modal instance opens up? An example will greatly help please ..

xmlking commented 9 years ago

I used a flag https://github.com/xmlking/spa-starter-kit/blob/master/app/common/controllers/LoginController.js

Mr-Anonymous commented 9 years ago

Thanks heaps for that @xmlking That certainly gives me an idea now on how to approach this. Thanks again for helping. I was stuck on that for a long time wondering how to resolve it. Much appreciated. :)