Skip to content

Instantly share code, notes, and snippets.

@jdc18
Created June 17, 2015 22:39
Show Gist options
  • Save jdc18/c26ea17487d2dfc68b35 to your computer and use it in GitHub Desktop.
Save jdc18/c26ea17487d2dfc68b35 to your computer and use it in GitHub Desktop.
app.factory('authInterceptor', function($q, Auth) {
return {
request: function (config) {
var deferred = $q.defer();
if (Auth.authz.token) {
console.log("entro")
Auth.authz.updateToken(5).success(function() {
config.headers = config.headers || {};
config.headers.Authorization = 'Bearer ' + Auth.authz.token;
deferred.resolve(config);
}).error(function() {
deferred.reject('Failed to refresh token');
});
}
return deferred.promise;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment