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

64
Vistas
React ApiConfiguration to listen to bearerToken changes?

I have an ApiConfiguration file which manages the middleware for API requests to the backend.

I have a login component that sets the bearer token to the document.cookie

and I am able to make requests to api by this config (OPEN API CLI GENERATOR)

    export const userApi = new UserApi(configuration).withPreMiddleware(
  (context): any => {
    // Always get update the Api Configuration with new Bearer Token.
    let newBearer: string | undefined;
    newBearer = Cookies.get("bearer");
    // TODO: use JWT-DECODE compare the expiration date and use refresh HOOK
    const doesBearerExist = apiConfigParams?.headers?.Authorization;
    if (!doesBearerExist) {
      context.init.headers = { Authorization: "bearer " + newBearer };
    }
    return context;
  },
);

One major problem I am having is, when I set new bearer token to document, this config does not retrieve the latest token unless I manually refresh the web client.

How do I set new bearer token? I'm not sure?

Either listening to changes? or making a function that gets called every time token changes? (How does that work?)

Thanks

about 4 years ago · Juan Pablo Isaza
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