angularjs - prevent user to access if has not logged in (only login/register views) -
i creating app ionic. need when user not logged, , him go state/page not log/register view, app move login or register.
but code generates 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 else if statement, problem same.
$rootscope.$on('$statechangestart', function(event, tostate, fromstate){ if(!userfactory.isloggedin() && tostate.name !== 'login' ){ event.preventdefault(); $state.go('login'); } });
any solution?
thanks!
pd: sorry poor english.
Comments
Post a Comment