I put in place a simple login system in my angular application similar to the one at http://demos.angularcode.com/angularcode-authentication-app/#/login
The problem that I'm facing now is that if I try to access a page when I'm not logged in, it first displays the restricted page for a second before redirecting to login.
You can see this behaviour if you try to go directly to the page http://demos.angularcode.com/angularcode-authentication-app/#/dashboard
The earliest I can do the authentification check is in my module declaration:
angular.module('myApp', [])
.run(function() {
//check auth + redirect
}
Is there a way to not display the restricted page first before redirecting to login?
EDIT
I use $urlRouterProvider and $stateProvider to manage routes.
For example the home page:
app.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/home");
$stateProvider
.state('home', {
url : '/home',
templateUrl : 'views/home.html'
})