Skip showing a view if user logged in

Hello all,
I have a little question. How to NOT show a login view if a user is logged in?
Currently I am checking an authentication token in login controller. While making a server call, I am blocking user interactions with ‘loading…’ overlay and if server responds with ‘true’ I am redirecting to main view (using state.go).
How can I skip showing login view altogether if user is authenticated?
The idea here is to prompt a users to login only one time, when they install the app.
Any help appreciated.
Thanks

Hello,

We have the same situation and solved it by storing the authenticated state locally, setting the $rootScope.authenticated in the config and checking it on any state change.

$rootScope.$on(’$stateChangeStart’,
function(event, toState, toParams, fromState, fromParams) {
if (toState.name != ‘login’) {
if (!$rootScope.authenticated) {
$state.go(‘login’);
}
}
});
}])

Hope this helps

@scottmizo thanks for the reply. So what is your first view? I assume that your main page is shown first. Do you check that with token agains any server side? At what point?
Thanks

Yes … the first view is the main page. If not authenticated, it goes directly to the login page at which point we go to the server to get a token. We never revalidate the token because we want people to use the app off-line. We just set an expiration on the token so that they must re-authenticate every so often. If you wanted to validate an existing token, I would do that in the controller of login and bypass any user interaction if the token was valid.

Thanks a lot! I thinks my problem is that my first view is the login. I will cange it to main view.

Thanks a lot.