Skip to content

Commit

Permalink
Check when API is removed to delete its cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
adri9valle committed Aug 2, 2019
1 parent 2a57fda commit 8d4ef47
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions public/services/app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export class AppState {
this.navigate = {};
}


//Gets all the extensions
getAllExtensions() {
return this.$cookies.getObject('extensions');
}

//Extensions setters and getters
getExtensions(id) {
const current = this.$cookies.getObject('extensions');
Expand Down
19 changes: 19 additions & 0 deletions public/services/resolves/settings-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,25 @@ export function settingsWizard(
return deferred.resolve();
};

const cleanApisCookies = () => {
console.log('cleaning apis cookies.')
genericReq
.request('GET', '/api/apis')
.then(data => {
const hosts = data.data || [];
const hostKeys = hosts.map(h => Object.keys(h)[0]);
const extensions = appState.getAllExtensions();
const extensionsKeys = Object.keys(extensions);
const diff = extensionsKeys.filter(e => !hostKeys.includes(e));
diff.map(d => appState.removeExtensions(d));
})
.catch(error => {
errorHandler.handle(error);
});
};

cleanApisCookies();

const currentParams = $location.search();
const targetedAgent =
currentParams && (currentParams.agent || currentParams.agent === '000');
Expand Down

0 comments on commit 8d4ef47

Please sign in to comment.