Created
February 15, 2016 18:38
-
-
Save ryedin/dcef6dce88dec80ab84a 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
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