Hey - are you trying to implement the Implicit Grant method?
You shouldn’t need to fetch anything here. The token is included in the URL when the user grants access and returns to your app.
The getAccessToken() function can check for the token with a regex like so (I did this project using the old video tutorial, so it may look different than what you have. The Spotify component has helper functions for authorization, serach and saving playlists.)
let accessToken;
const Spotify = {
getAccessToken() {
if (accessToken) {
return accessToken;
}
// check for an access token
const accessTokenMatch = window.location.href.match(/access_token=([^&]*)/);
const expiresInMatch = window.location.href.match(/expires_in=([^&]*)/);
if (accessTokenMatch && expiresInMatch) {
accessToken = accessTokenMatch[1];
const expiresIn = Number(expiresInMatch[1]);
// This clears the token & expiry so we can get a new token when it expires
window.setTimeout(() => (accessToken = ""), expiresIn * 1000);
window.history.pushState("Access Token", null, "/");
return accessToken;
...
}