Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Headers in react don't persist

Okay so this may be a really junior question but I have just started working with react and I don't know much about it.

The thing is: I'm trying to code an ecommerce. To access a certain page of the website (productos), you need a token (to be logged in, authenticated). So the first thing I do in each page (that requires to be logged in) is to check if the user is logged in, and if it is, I take the token and I set it to the header like this:

function Products()
{
Promise.all([
    fetch('http://localhost:3001/login',
    {
      method: 'get',
      headers: new Headers({
        'Authorization': sessionStorage.getItem("token"),
        'Content-Type': 'application/x-www-form-urlencoded'
      })
    }).then(value => value.json()), 
    fetch('http://localhost:3001/productos').then(value => value.json())
  ]).then((value) => {
    console.log(value)
  })
}

The first fetch is working fine, because it sets the header 'authorization' equals to the token of the user, BUT the second fetch doesn't have this header.

enter image description here

enter image description here

I thought that the header would persist... Since it doesn't, when the fetch of products tries to load the data it doesn't do it, because it doesn't have the header 'authorization'...

Could somebody help me out please?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!