Skip to content

Instantly share code, notes, and snippets.

@ryedin
Created February 15, 2016 18:38
Show Gist options
  • Save ryedin/dcef6dce88dec80ab84a to your computer and use it in GitHub Desktop.
Save ryedin/dcef6dce88dec80ab84a to your computer and use it in GitHub Desktop.
app.config(function($httpProvider) {
$httpProvider.interceptors.push(function($q, $location) {
return {
// Reject unauthenticated requests
responseError: function(rejection) {
if (rejection.status === 401) {
$location.nextAfterLogin = $location.path();
//prevent redirect to login or logout after login
if ($location.nextAfterLogin === '/logout' ||
$location.nextAfterLogin === '/login') {
delete $location.nextAfterLogin;
}
$location.path('/login');
}
return $q.reject(rejection);
}
};
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment