-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthInterceptorService.js
More file actions
31 lines (26 loc) · 940 Bytes
/
authInterceptorService.js
File metadata and controls
31 lines (26 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(function (angular) {
'use strict';
//// JavaScript Code ////
function AuthInterceptorServiceFactory($q, $location, authService, localStorageService) {
function _request(config) {
config.headers = config.headers || {};
var authData = localStorageService.get('authorizationData');
if (authData) {
config.headers.Authorization = authData.token;
}
return config;
}
function _responseError(rejection) {
if (rejection.status === 401) {
$location.path(authService.getLoginUri());
}
return $q.reject(rejection);
}
return {
request : _request,
responseError : _responseError
};
}
//// Angular Code ////
angular.module('LoopbackAuthService').factory('authInterceptorService',AuthInterceptorServiceFactory);
})(angular);