Skip to content

Commit 1b4c328

Browse files
committed
- try to debug auth problem
1 parent 93d0e2f commit 1b4c328

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

tools/spotify_music_quiz_cards.html

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
}
229229

230230
const response = await spotifyFetch(`https://api.spotify.com/v1/playlists/${playlistId}/tracks`);
231-
if (!response) return []; // Handle case where auth refresh was triggered
231+
if (!response) return [];
232232

233233
const data = await response.json();
234234
return data.items
@@ -387,33 +387,27 @@ <h3 class="title">${track.name}</h3>
387387
}
388388

389389
async function spotifyFetch(url, options = {}) {
390-
console.log('Making request to:', url);
391-
392-
const token = localStorage.getItem('spotify_access_token');
393-
console.log('Using token:', token?.substring(0, 10) + '...');
394-
395390
const response = await fetch(url, {
396391
...options,
397392
headers: {
398-
'Authorization': `Bearer ${token}`,
393+
'Authorization': `Bearer ${localStorage.getItem('spotify_access_token')}`,
399394
...options.headers
400395
}
401396
});
402397

403398
if (response.status === 401) {
404-
console.log('Got 401 error for URL:', url);
405-
console.log('Full response:', response);
406-
// Let's check if we just got redirected back from auth
407-
const hashParams = getHashParams();
408-
if (hashParams.access_token) {
409-
console.log('We already have a new token but still getting 401s');
410-
// Something else is wrong - maybe token isn't being stored properly
411-
return response;
412-
}
413-
refreshAuth();
399+
localStorage.clear();
400+
sessionStorage.clear();
401+
const clientId = localStorage.getItem('spotify_client_id');
402+
const scope = 'streaming user-read-email user-read-private user-modify-playback-state playlist-read-private';
403+
window.location.href = `https://accounts.spotify.com/authorize?client_id=${clientId}&response_type=token&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${encodeURIComponent(scope)}`;
414404
return;
415405
}
416406

407+
if (!response.ok) {
408+
throw new Error(`API request failed with status ${response.status}`);
409+
}
410+
417411
return response;
418412
}
419413
</script>

0 commit comments

Comments
 (0)