-
Hello all. I'm using remix with express and do user authentication via oauth2. Everything is written in typescript. Right now, all authentication logic (routes, session, etc.) is implemented in remix. As I don't have any data storage at hand, the id and refresh tokens are stored as encrypted cookies. Basically this setup works all fine. However, for nested routes, each loader basically needs to do the same things: parse the cookie first, decrypt the id token next, maybe fetch a new id token using the refresh token that has also be decrypted and than write that new (encrypted) id token back to the response header. As this also happens when rendering the initial HTML on the server, I would like to put it somewhere, so that I only have to do it once per request. So far, I tried three separate things:
Long story short: what is the best way to share (per-request) data/instances between loaders? I think this all wouldn't be a problem, if I could define the Sorry, if this is a duplicate. I couldn't find something similar, but realized a lot of discussions around loaders and sharing state and stuff. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It's not possible to share data between loaders, this is because:
Because of all of this, specially the last one, each loader should run all the logic it needs, if a loader needs the access token and refresh token you will need to do it on that loader too. What I recommend is to:
|
Beta Was this translation helpful? Give feedback.
It's not possible to share data between loaders, this is because:
/parent/child1
and navigate to/parent/child2
because/parent
didn't changed Remix will only call the loader of child2.Because of all of this, specially the last one, each loader should run all the logic it needs, if a loader needs the access token and refre…