Replies: 2 comments 1 reply
-
@atifc Did you figure out a good solution for this? The |
Beta Was this translation helpful? Give feedback.
-
@atifc I was able to implement a temporary workable fix for this same issue that I too faced.
Now one issue I face is during the page load or refresh the request to fetch the token is made twice. I have not investigated the cause of this yet, so I don't know if it is mistake of my application or react-router specific. I hope there is 'beforeLoader' kind of functionality that enables such scenarios where we can switch to sequential instead of parallel for particular situations. |
Beta Was this translation helpful? Give feedback.
-
I'm using createBrowserRouter with loaders on several routes.
Here is my current setup:
app.tsx:
index.tsx:
The keycloakservice handles initial authentication, token update etc.
The httpservice checks if the token is present and configures axios interceptor to attach the token to the authorization header and refreshes the token afterwards.
This all works fine and well, except for the very first API call which originates from the "loadFrontpage" loader, since react-router executes all loaders in parallel, so that first call fails since the token will not be set in time.
Does anyone have a suggestion on a way to make sure that the authentication has finished initializing before the loaders are allowed to execute?
Beta Was this translation helpful? Give feedback.
All reactions