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

140
Visualizações
React how to get accessToken?

I want to send a post with fetching. But I get 401 error: www-authenticate: Bearer error="invalid_token". I am using Userfront.accessToken() but It did not work.

How can I get accestoken for bearer authentication?

const submit = (e) => {
    e.preventDefault();
    const data = new FormData(form.current);
    fetch(process.env.REACT_APP_ENDPOINT + "user/me/contract", {
      method: "POST",
      body: data,
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${Userfront.accessToken()}`,
      },
    }).then((res) => res.json());
  };

Note:

console.log(`Bearer ${Userfront.accessToken()}`);

Bearer [object Object]

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

0

JSON.stringify(Userfront.accessToken()) please stringify that object to understand what is going on there then if there is accessToken returning from that function put that string.

I just realized in the doc;

To handle a request like this -Userfront.accessToken()-, your backend should read the JWT from the Authorization header and verify that it is valid using the public key found in your Userfront dashboard.

https://userfront.com/guide/auth/

fetch('https://api.example.com', {
  method: 'GET'
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${Userfront.tokens.accessToken}`
  }
});
about 4 years ago · Juan Pablo Isaza Relatório

0

Can you try this? I see this from https://userfront.com/guide/auth/

  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${Userfront.tokens.accessToken}`
  }
about 4 years ago · Juan Pablo Isaza Relatório

0

Thank you all for your answers.

Authorization: `Bearer ${localStorage.getItem("fray_access_token")}`,

In this application, token gets a different name. When I look from inspects, I use it and it works!

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