Skip to content

Commit

Permalink
added checkToken
Browse files Browse the repository at this point in the history
  • Loading branch information
synan798 committed Dec 23, 2024
1 parent 893527f commit b57dc96
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,37 @@ onMounted(async () => {
setLevelbar(70);
await fetchUser();
await fetchGames();
checkToken();
intervalId.value = await setInterval(() => {
fetchGames()
fetchGames();
checkToken();
}, 15000); // 15 seconds
});
onBeforeUnmount(() => {
clearInterval(intervalId.value);
});
async function checkToken() {
try {
const res = await fetch(`https://api.spotify.com/v1/me`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${useCookie('sb-provider-token').value}`,
},
});
if (!res.ok) {
console.error(`Error: ${res.status} - ${res.statusText}`);
navigateTo('/login');
}
} catch (error) {
console.error('Failed to validate token:', error);
navigateTo('/login');
}
}
function setLevelbar(newValue: number) {
const levelbar = document.getElementById('levelbar')
if (levelbar) {
Expand Down

0 comments on commit b57dc96

Please sign in to comment.