Cannot set window.location in jammming project

Hi everyone! I am working on the jammming project and encountered a problem. I was trying to get an access token from the Spotify api with these code:

const accessUrl = `${authEndpoint}?client_id=${clientId}&response_type=${responseType}&redirect_uri=${redirectUri}`;
window.location.href = accessUrl;
const hash = window.location.hash;
console.log(accessUrl);
console.log(window.location.href);

However, the window.location.href doesn’t seem to change no matter what I do. I logged accessUrl and it is what I expect, but window.location.href is always http://localhost:3000/. I have no idea why that is. Any help is appreciated.

In your code, window.location.href should change as expected when you assign access URL to it. Here are a few things to check:

Make sure JavaScript isn’t being blocked by the browser or security settings.
Verify accessUrl is a valid URL: Confirm it includes a full path with https://.
Disable any CORS-related browser plugins that may interfere with the redirection.
Ensure no additional code resets the href or prevents the redirect.
If issues persist, you might add console.log after setting window.location.href to verify the flow.

Nvm I figured it out. The problem is the app refresh when I change the link. I fixed it by adding e.preventDefault to the button. Not sure why refreshing causes the problem though. Maybe refreshing stops the process of changing URL?