Skip to content Skip to sidebar Skip to footer

How To Integrate GetAccessToken With Fetch Function To Load Data From DRF Backend To React Frontend?

React newbie here, but proficient in Django.I have a simple fetch function which worked perfectly but then my project had no login authentication involved. Now that I have configur

Solution 1:

If you're looking for a way how to pass headers in fetch request, it's pretty straight forward:

await fetch('http://127.0.0.1:8000/api/allorders/', {
 headers: {
   // your headers there as pair key-value, matching what your API is expecting, for example:
   'details': getAccessToken()
  }
})

Just don't forget to import your getAccessToken const, if that's put it another file, and I believe that would be it. Some reading on Fetch method


Post a Comment for "How To Integrate GetAccessToken With Fetch Function To Load Data From DRF Backend To React Frontend?"