Set sessionStorage if an auth token exists in the hash
This commit is contained in:
parent
4a68bbc58e
commit
c7add28aa8
1 changed files with 15 additions and 23 deletions
38
src/App.vue
38
src/App.vue
|
|
@ -37,32 +37,24 @@ export default {
|
||||||
|
|
||||||
if ( this.is_dev || this.is_preview ) { return true; };
|
if ( this.is_dev || this.is_preview ) { return true; };
|
||||||
|
|
||||||
// Check to ensure the authorization was a success
|
|
||||||
if (params.get(`access_token`)) {
|
if (params.get(`access_token`)) {
|
||||||
|
if (sessionStorage.getItem(this.storage_key.state) === params.get(`state`)) {
|
||||||
|
console.info(`State compare success`)
|
||||||
|
|
||||||
// Check if we compare state
|
// Modify sessionStorage
|
||||||
if (process.env.NODE_ENV === `production`) {
|
sessionStorage.setItem(this.storage_key.token, params.get(`access_token`));
|
||||||
|
sessionStorage.removeItem(this.storage_key.state);
|
||||||
// Compare given state to localstorage state
|
|
||||||
let LS_state = localStorage.getItem(`top-spotify-state`);
|
|
||||||
if (LS_state == params.get(`state`)) {
|
|
||||||
console.info(`State compare success`)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
console.error(`State compare failed`)
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let error = (new URLSearchParams(window.location.search.slice(1))).get(`error`)
|
|
||||||
|
|
||||||
// Authorization failed, error to the user
|
|
||||||
if (error !== null) {
|
|
||||||
window.location.hash = ``;
|
window.location.hash = ``;
|
||||||
}
|
} else {
|
||||||
return false;
|
console.error(`State compare failed`);
|
||||||
}
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
if (sessionStorage.getItem(this.storage_key.token)) {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue