jhipster/generator-jhipster — pull request #802 by tgillieron (2014-11-25 16:26:47+00:00)
Title: remove flicker when trying to access unauthorized URL.

When loading an unauthorized URL the page can flicker. It is caused by the instantiation of the associated controller and template before the AuthenticationSharedService.valid method has been resolved.

This comportment came from the way the authentication are resolved:

1. Upon an URL change, a $routeStartChange event is emitted.
2. On $routeStartChange event, an asynchronous validation (AuthenticationSharedService.valid) is called.
3. The function associated to the $routeStartChange event continue without being stopped and emits a $routeChangeSuccess event.
4. On $routeChangeSuccess event, the controller and template associated to the view are instantiated and rendered.
5. The AuthenticationSharedService.valid method is finally resolved and emits either an event:auth-notAuthorized or event:auth-loginRequired event that trigger an url change, thus the flicker.

With the new implementation:

1. The AuthenticationSharedService.valid method becomes a promise
2. A $secureRouteProvider provider decorating the $routeProvider with a new method, whenAuthenticated(path, route), is implemented.
* This method adds the AuthenticationSharedService.valid method to the route.resolve object.
* Because the AuthenticationSharedService.valid method is now in the resolve object, the route will wait for it to be resolved before instantiating the controller and template.
* If the AuthenticationSharedService.valid method is rejected, the $routeChangeSuccess event will not be emitted and the user will be redirected to the login or error page without the unauthorized URL being rendered.
3. Every call to the $routProvider.when method is replaced by $secureRouteProvider.whenAuthenticated