i am creating an app with Ionic. I need that when the user is not logged, and him go to another state/page that it is not the log/register view, the app move it to the login or register.
but my code generates a loop.
$rootScope.$on('$stateChangeStart', function(event, toState, fromState){
if(!UserFactory.isLoggedIn() && (toState.name !== 'login' || toState.name !== 'register') ){
event.preventDefault();
$state.go('login');
}else if(toState.name == 'login' || toState.name == 'register'){
$state.go(toState.name);
}
});
** UPDATE **
i removed the else if statement, but the problem is the same.
$rootScope.$on('$stateChangeStart', function(event, toState, fromState){
if(!UserFactory.isLoggedIn() && toState.name !== 'login' ){
event.preventDefault();
$state.go('login');
}
});
any solution?
thanks!
pd: Sorry for my poor English.