Created
February 10, 2015 15:06
-
-
Save tkh44/c4a593560a738a02073d 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
class HttpAuthService { | |
constructor($q, $injector) { | |
super($q); | |
angular.extend(this, {$q, $injector}); | |
} | |
request(config) { | |
//console.log(config); | |
return config; | |
} | |
requestError(rejection) { | |
//console.log(rejection); | |
return this.$q.reject(rejection); | |
} | |
response(config) { | |
var UserService = this.$injector.get('UserService'); | |
if (this.isApiRequest(config.url)) { | |
if (this.UserService.isAuthorized()) { | |
// This is just a prototype UserService is a fiction of my imagination | |
} | |
} | |
return config; | |
} | |
responseError(rejection) { | |
//console.log(rejection); | |
return this.$q.reject(rejection); | |
} | |
isApiRequest(url) { | |
return url.search('/external/api') > -1; | |
} | |
static httpAuthFactory($q, $injector) { | |
return new HttpAuthService($q, $injector); | |
} | |
} | |
HttpAuthService.httpAuthFactory.$inject = ['$q', '$injector']; | |
angular.module('mailApp').config(($provide, $httpProvider) => { | |
$provide.factory('authorizeInterceptor', HttpAuthService.httpAuthFactory); | |
$httpProvider.interceptors.push('authorizeInterceptor'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment