I am not even sure I asked it right. I am making an app using the spotify API. I use the base code from their site: https://github.com/spotify/web-api-auth-examples/blob/master/authorization_code/app.js. You might need to read the “Authorization code flow” part of the following link before you understand what is going on: https://developer.spotify.com/documentation/general/guides/authorization-guide/

Basically with the spotify api, you need an access token to be able to access any endpoint. Before i implemented react router, the token persisted on the url you will normally see here:

r/webdev - Mix express routes with react routes

So it would be localhost:3000/accesstoken=gibberish no matter what component was being rendered. It would just stay like that.

If you look at line 107 on the GitHub link, it allows me to make api calls from my browser by passing the token to my browser. In my case that’s localhost:3000

r/webdev - Mix express routes with react routes

my code

Now i am trying to implement routing but the token disappears from the URL:

r/webdev - Mix express routes with react routes

token in URL

Previously, since I did not have routes, all components would be rendered under http://localhost:3000. but now……

r/webdev - Mix express routes with react routes

token disappears when i change components(routes)

I am guessing its not persisting because the res.redirect only says add access token to “http://localhost:3000/#” but now that i have specified links, Its not working anymore. The thing is, I need that token to be on all routes. I dont know how to put the access token in the path considering it changes dynamically so i cant hard code it. Do i pass the token to all routes as a prop?



Source link

Write A Comment