Skip to content

Commit 93d0e2f

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

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

tools/spotify_music_quiz_cards.html

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@
211211
const [key, value] = param.split('=');
212212
hashParams[key] = decodeURIComponent(value);
213213
});
214+
215+
// If we got a new token, save it immediately
216+
if (hashParams.access_token) {
217+
console.log('Got new token from hash:', hashParams.access_token.substring(0, 10) + '...');
218+
localStorage.setItem('spotify_access_token', hashParams.access_token);
219+
}
220+
214221
return hashParams;
215222
}
216223

@@ -380,24 +387,33 @@ <h3 class="title">${track.name}</h3>
380387
}
381388

382389
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+
383395
const response = await fetch(url, {
384396
...options,
385397
headers: {
386-
'Authorization': `Bearer ${localStorage.getItem('spotify_access_token')}`,
398+
'Authorization': `Bearer ${token}`,
387399
...options.headers
388400
}
389401
});
390402

391403
if (response.status === 401) {
392-
// Token is invalid, refresh authentication
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+
}
393413
refreshAuth();
394414
return;
395415
}
396416

397-
if (!response.ok) {
398-
throw new Error(`API request failed with status ${response.status}`);
399-
}
400-
401417
return response;
402418
}
403419
</script>

0 commit comments

Comments
 (0)