https://auth0.com/blog/2014/01/07/angularjs-authentication-with-cookies-vs-token/
//Global AuthInterceptor
HandpickApp.factory('authInterceptor', function ($rootScope, $q, localStorageService) {
return {
request: function (config) {
debugger;
config.headers = config.headers || {};
if (localStorageService.get('bearToken')) {
config.headers.Authorization = 'Bearer ' + localStorageService.get('bearToken');
}
return config;
},
response: function (response) {
if (response.status === 401) {
// handle the case where the user is not authenticated
}
return response || $q.when(response);
},
responseError: function (rejection) {
if (rejection.status === 401) {
// handle the case where the user is not authenticated
//TODO
alert("401 E");
}
}
};
});
HandpickApp.config(function ($httpProvider) {
$httpProvider.interceptors.push('authInterceptor');
});