Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda