AngularJS Login and Authentication in each route and controller

Use below code

 app.run(function($rootScope, $state, localStorageService) {
  $rootScope.$on('$stateChangeStart', function(event, current) {
      if (current.url != '/login' && current.url != '/signup' &&
              current.url != '/createPassword' && current.url !=
                  '/forgotPassword' && localStorageService.get('user') == null) {
          event.preventDefault();
          $state.go('login');
      }
  })
});


No comments:

Post a Comment