Optimizing Authentication Token Handling in Remix Loaders: Seeking Best Practices
Hi, I'm looking for some advice
I'm using effect in remix, one request is handled by running multiple loaders simultaneously.
Each of my loaders is modelled as an effect, run by a
ManagedRuntime
ManagedRuntime
.
I managed to pass a request id to each of the loaders, so they have some "sense" of whether they belong to the same request or not.
Typically most of them loads authentication data (checks the cookies for a token, checks if valid, and if stale, refreshes it).
I'm looking for the best way to only do this process once per request - I mostly don't want to refresh the token multiple times while handling the same request.
Currently I'm using a
RequestResolver
RequestResolver
with 5s cache with the request id as the key, and it works, but the solutions seems "not ideal" to me.
I tried to batch those auth effects but it doesn't work, only the caching.
What would be the "correct solution" for this type of problem?