Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

374
Visualizações
Why axios remove "Bearer" string from authorization header?

I've had a problem with axios and GET request with using Bearer token. Here is my code:

      const response = await axios.post("/auth/login", {
        ...form
      });

      const token = response["token"];
      if (token) {
        localStorage.setItem("session", token);

        console.log(token); //a234o2i3nr203fn20jef0293...
        const tokenHeader = {
          authorization: `Bearer ${token}`
        }

        const projects = await axios.get('/projects', { headers: { "authorization": `Bearer ${token}`}});
        console.log(projects); //UNAUTHORIZED

      }
        

After login to account I want to immediately fetch data about projects, so I use axios and try to use axios.get with authorization header. But, for unknown for me reason, to my server part request has been delivered but without Bearer string before my token, my server had this on this request:

headers: {
    authorization: "a234o2i3nr203fn20jef0293..." //axios remove `Bearer` string?
}

becuase of this, I cannot return any value because my server return me unauthorized cause this:

    const token = authHeaders && authHeaders.split(" ")[1];

return me null instead of token.

Can someone tell me what is wrong with this axios request?

Thanks for any help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try writing "Authorization" and not "authorization". I've had this kind of problems before.

const projects = await axios.get('/projects', { headers: { "Authorization": `Bearer ${token}`}});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda