Jammming step 83 redirect

Hi there! I’ve just finished the Jammming project (https://www.codecademy.com/paths/web-development/tracks/front-end-applications-with-react/modules/jammming/projects/jammming-prj)

I have a problem with understanding step 83. Could anyone explain to me why we should check accestoken match before redirecting a user to the accesURL? Shouldn’t we redirect user to the accesURL first?

hi Shumil,

you need to check if you already have the accessToken because you are going to use function getAccessToken() a couple more times.

Yes, for the initial state when a user downloads the page for the first time they will be always redirected.
But once we have his accessToken it’s valid for an hour. During this hour users might want to do new search or save playlist to Spotify - all these actions will reqire a new fetch to API thus the accessToken. This is when checking if the accessToken is already received comes in handy.

1 Like

Thank you for the explanation!

1 Like