Created
February 8, 2016 14:17
-
-
Save niisar/77dbb63b766940e74ee3 to your computer and use it in GitHub Desktop.
AngularJSAuthentication.WEB
This file contains hidden or 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
| define(['app'], function (app) { | |
| app.service('authInterceptorService', function ($q, $location, $localStorage) { | |
| var authInterceptorServiceFactory = {}; | |
| var _request = function (config) { | |
| config.headers = config.headers || {}; | |
| var authData = $localStorage.authorizationData; | |
| if (authData) { | |
| config.headers.Authorization = 'Bearer ' + authData.token; | |
| } | |
| return config; | |
| } | |
| var _responseError = function (rejection) { | |
| if (rejection.status === 401) { | |
| // $state.go('login'); | |
| $location.path('/login'); | |
| } | |
| return $q.reject(rejection); | |
| } | |
| authInterceptorServiceFactory.request = _request; | |
| authInterceptorServiceFactory.responseError = _responseError; | |
| return authInterceptorServiceFactory; | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment