Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

62
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!