mirror of
https://github.com/mmumshad/ansible-playable.git
synced 2025-03-09 23:38:54 +00:00
Initial Commit
This commit is contained in:
commit
c92f737237
273 changed files with 16964 additions and 0 deletions
28
client/components/auth/interceptor.service.js
Normal file
28
client/components/auth/interceptor.service.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
'use strict';
|
||||
|
||||
export function authInterceptor($rootScope, $q, $cookies, $injector, Util) {
|
||||
'ngInject';
|
||||
|
||||
var state;
|
||||
return {
|
||||
// Add authorization token to headers
|
||||
request(config) {
|
||||
config.headers = config.headers || {};
|
||||
if($cookies.get('token') && Util.isSameOrigin(config.url)) {
|
||||
config.headers.Authorization = `Bearer ${$cookies.get('token')}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
|
||||
// Intercept 401s and redirect you to login
|
||||
responseError(response) {
|
||||
if(response.status === 401) {
|
||||
(state || (state = $injector.get('$state')))
|
||||
.go('login');
|
||||
// remove any stale tokens
|
||||
$cookies.remove('token');
|
||||
}
|
||||
return $q.reject(response);
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue