Rutwick Gangurde Rutwick Gangurde - 2 months ago 32
AngularJS Question

AngularJs - Skip login page if already logged in

I have implemented an Authentication system for my app. I use

$routeChangeStart
(in run) to check if the user is logged in and redirect him to login if not. This works fine. But, I can access the login page via the url, I want to send the user to the dashboard if he's already logged in. What is the proper way to do this?

Answer

Try

$rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {}); 

Details here https://docs.angularjs.org/api/ng/service/$location