Skip to content

Commit

Permalink
use angular interceptor to detect 401 and redirect to login page
Browse files Browse the repository at this point in the history
  • Loading branch information
whitews committed Jul 16, 2014
1 parent 6d49d93 commit c47c4e2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion static/ng-app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ var app = angular.module(
]
);

app.factory('LoginRedirectInterceptor', function($q, $window) {
return {
responseError: function(rejection) {
if (rejection.status == 401) {
$window.location.assign('/login');
} else {
return $q.reject(rejection);
}
}
};
});

var MODAL_URLS = {
'SUBJECT_GROUP': 'static/ng-app/partials/subject-group-form.html',
'SUBJECT': 'static/ng-app/partials/subject-form.html',
Expand All @@ -38,7 +50,9 @@ var MODAL_URLS = {
'BEAD_SAMPLE_DELETE': 'static/ng-app/partials/bead-sample-delete.html'
};

app.config(function ($stateProvider, $urlRouterProvider) {
app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
$httpProvider.interceptors.push('LoginRedirectInterceptor');

$urlRouterProvider.otherwise("/");

$stateProvider.state({
Expand Down

0 comments on commit c47c4e2

Please sign in to comment.