Created
November 19, 2015 15:58
-
-
Save caferrari/c6df6c576ecec727146e 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
(function() { | |
'use strict'; | |
angular.module('App') | |
.factory('authInterceptor', ['API', 'auth', authInterceptor]); | |
function authInterceptor(API, auth) { | |
return { | |
request: function(config) { | |
if (config.url.indexOf(API) === 0) { | |
config.headers.Authorization = 'Bearer ' + auth.getToken(); | |
config.headers.Accept = 'application/json'; | |
} | |
return config; | |
}, | |
response: function(res) { | |
var token = res.headers('X-Token'); | |
if (token) { | |
auth.setToken(token); | |
} | |
return res; | |
}, | |
}; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment