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

66
Visualizações
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 à 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