Use anonymous function as interceptor.

This commit is contained in:
Alexis Lahouze 2017-07-08 00:17:15 +02:00
parent d6eb6781c6
commit 9a7d3938aa

View File

@ -74,28 +74,24 @@ module.exports = angular.module('accountant.login', [
}; };
}) })
.factory('sessionInjector', function($storage) {
var sessionInjector = {
request: function(config) {
var access_token = $storage.session.get('access_token');
if (access_token) {
//var tokenType = $storage.get('token_type');
var tokenType = 'Bearer';
var authorization = tokenType + ' ' + access_token;
config.headers.authorization = authorization;
}
return config;
}
};
return sessionInjector;
})
.config(function($httpProvider, $storageProvider) { .config(function($httpProvider, $storageProvider) {
// Define interceptors. // Define interceptors.
$httpProvider.interceptors.push('sessionInjector'); $httpProvider.interceptors.push(function($storage) {
return {
request: function(config) {
var access_token = $storage.session.get('access_token');
if (access_token) {
//var tokenType = $storage.get('token_type');
var tokenType = 'Bearer';
var authorization = tokenType + ' ' + access_token;
config.headers.authorization = authorization;
}
return config;
},
};
});
// Configure storage // Configure storage
// Set global prefix for stored keys // Set global prefix for stored keys