I have one main controller for my app – AppCtrl
and use ui-router. How can I make secured states?
$rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){
var authorization = toState.data.authorization;
if(!Security.isAuthenticated() && authorization != false)
$location.path('/login');
});
For example I want to make books
and authors
states secured, and login
state not secured.
.state('login', {
url: '/login',
templateUrl: /**/,
controller: /**/,
data: {
authorization: false
}
})
.state('books', {
url: '/books',
templateUrl: /**/,
controller: /**/,
data: {
authorization: true
}
})
.state('authors', {
url: '/authors',
templateUrl: /**/,
controller: /**/,
data: {
authorization: true
}
})
Security.isAuthenticated()
function returns boolean. When I open /books
everything works perfectly, page are being redirected to /login
, when after redirecting I open /authors
, page loads and it’s content are shown, but browser’s url is /login
, so page being redirected, but somehow it’s content are shown.