Created
June 3, 2014 12:26
-
-
Save zolotyh/f94ea2fffdf36c0ae58e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Intercept 401s and redirect you to login | |
$httpProvider.interceptors.push(['$q', '$location', function($q, $location) { | |
return { | |
'responseError': function(response) { | |
if(response.status === 401) { | |
$location.path('/login'); | |
return $q.reject(response); | |
} | |
else { | |
return $q.reject(response); | |
} | |
} | |
}; | |
}]); | |
}) | |
.run(function ($rootScope, $location, Auth) { | |
// Redirect to login if route requires auth and you're not logged in | |
$rootScope.$on('$routeChangeStart', function (event, next) { | |
if (next.authenticate && !Auth.isLoggedIn()) { | |
$location.path('/login'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment