let vm: any = this;
vm.apiService
.authenticateGoogleToken('googleIdTokenGoesHere')
.toPromise()
.then(result => {
console.log("google config result ", result);
return result;
})
.then(data => {
console.log("from google auth api ", data);
vm.apiService
.getNewApiKey()
.toPromise()
.then(apiKey => {
if (apiKey == null) {
alert('Sorry cant find api key for the user');
return false;
} else {
// we got a valid api key
let nextAction = 'apiKeyRetreived'; // i want nextAction to be passed to the next nest
let dbFields = {
apiKey : apiKey
}
if (1!=2){
nextAction = 'reloadSitesSectors';
}
// update the changes now
vm.configService.updateConfiguration(dbFields).subscribe(updatedConfig => {
console.log("configuration after update is ", updatedConfig);
return nextAction
},
error=> {
alert('failed')
return false;
}
);
}
})
.then(action => {
// now action is always 'undefined'
console.log("logout of google no matter what but ordered to do ", action);
// we will logout still no matter what but see if we need to get
// sectors and cells for the district or leave things as they are
if (action == 'reloadSitesSectors'){
// we should clear
vm.geoLocationService.clearSectors().subscribe(
done => {
vm.getSectors();
vm.getSites();
},
error => {
console.log("there was an error deleting current sectors");
}
);
}
// logout of google no matter what
vm.apiService.googleTokenLogout().subscribe(
logOut => {
console.log("google logout info ", logOut);
},
err => {
// likely the cookie wasn't found so server don't know what to logout exactly
console.log("error logging out from auth ", err);
}
);
});
})
.catch(err => {
console.log("err ", err);
});