witoldsz / angular-http-auth

MIT License
2.38k stars 417 forks source link

Scope out of date when using a hard redirect to a login page. #45

Closed vilmosioo closed 10 years ago

vilmosioo commented 10 years ago

If 'event:auth-loginRequired' triggers a redirect to a login page and if the 'do-something-with-response' handler modifies the $scope, upon 'authService.loginConfirmed()', the reference to $scope is out of date (a new scope was generated upon navigating back to the page that generated the 401).

This causes all sorts of problems such as double requests in controllers etc...

Any idea how to implement this with a hard-redirect?

witoldsz commented 10 years ago

Check the example application I have prepared. The general rule is this: never redirect anywhere when you get 401, because you will destroy user's context. Whatever they are doing, if you redirect, they will loose their work.

What should you do? Keep the login form hidden. It should be part of the application page. Once you get 401 - show the hidden login form and hide everything else. This is as simple as switching one class and let CSS do the work for you.

As I said, check the example application.

vilmosioo commented 10 years ago

I was afraid of this. My specs are based on an outdated server auth model... Sigh...

The example application is great, I had no issue creating a modal based login form. I guess I will have to do the same with the login page.

Thanks a lot for your help!