Created
March 29, 2016 01:59
-
-
Save leosilvadev/4fa5d6e4c5653d62669f to your computer and use it in GitHub Desktop.
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
angular.module('blogjs.autorizacao', ['blogjs.interceptadores']).config(function($httpProvider){ | |
$httpProvider.interceptors.push('AutorizadorInterceptor'); | |
}); |
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
angular.module('blogjs.interceptadores').factory('AutorizadorInterceptor', function interceptor($location) { | |
return { | |
request: function (config) { | |
var usuarioLogado = localStorage.getItem('usuarioLogado'); | |
if ( usuarioLogado ) { | |
config.headers['Authorization'] = 'Basic ' + btoa(usuarioLogado.login+':'usuarioLogado.senha); | |
} | |
return config; | |
}, | |
responseError: function(response) { | |
if (response.status === 401) { | |
$location.path('/login'); | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment