Skip to content

Instantly share code, notes, and snippets.

@mandado
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save mandado/34075e98470c1d43bb4a to your computer and use it in GitHub Desktop.

Select an option

Save mandado/34075e98470c1d43bb4a to your computer and use it in GitHub Desktop.
(function (module) {
'use strict';
module.run(['$rootScope', 'authService', '$location','$state', function ($rootScope, authService, $location, $state) {
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
console.log(toState);
if (toState.name === 'home') {
$location.path('/');
}
if (!authService.isLogged() && !$state.get(toState.name)) {
$location.path('/login');
}
});
$rootScope.$on('$stateNotFound ', function(event, unfoundState, fromState, fromParams){
console.log("nao achou...");
$location.path('/login');
});
$rootScope.$on('$locationChangeStart ', function(event, unfoundState, fromState, fromParams){
console.log("ERROR");
});
})(angular.module('authInterceptor', ['authService']));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment