Skip to content

Instantly share code, notes, and snippets.

@gblnovaes
Created July 30, 2015 15:19
Show Gist options
  • Save gblnovaes/c5b04bddbad52a9f403b to your computer and use it in GitHub Desktop.
Save gblnovaes/c5b04bddbad52a9f403b to your computer and use it in GitHub Desktop.
Teste
var service = angular.module('inApp');
service.factory('AuthService', function($http,$location,$window) {
return {
hasToken: function() {
// verifica se tem token senao tiver direciona para o login.
var token = $window.localStorage.getItem('access_token');
var redirect = '/#';
if(token == null || !token){
$window.location.href = redirect;
}
},
getToken: function() {
// consultar local store
// se nao existir tiro o cara
// se existir monto no padrao de devolucao
var token = $window.localStorage.getItem('access_token');
var redirect = '/#';
if(token == null || !token){
$window.location.href = redirect;
}else{
console.log($window.localStorage.getItem('access_token'));
var header = {
headers: {
'Authorization': 'Baerer ' + token
}
};
return header;
}
}
};
});
service['$inject'] = ['$http', 'AuthService','$location','$window'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment