Implementing a refresh token flow as explained in https://supertokens.com/docs/session/common-custom...
n
Implementing a refresh token flow as explained in https://supertokens.com/docs/session/common-customizations/sessions/ssr#3-implementing-the-refresh-session-flow-refresh-session-pagr causes the whole web app to 'flash' every time a token is refreshed, because we navigate to the /refresh-session page (using Remix in my example). Is there a way to refresh the token on the server during the request instead of redirecting to a front-end page that needs to do an API call and redirect back?
r
hey @nudjialz the refresh token is only saved on the client side, so using it on the server is not really possible.
n
I was just realizing that, I'm going to fiddle around a little longer 🙂 I might make a remix-specific package once I have figured out the most things
Thx for quick responses btw
r
thank you 🙂
n
Alright, just FYI, I have a route in Remix (with a loader, no page) that returns the expiration date of the current access token, then I have a hook in my root that calls this route every couple of seconds, if the token is about to expire, it will call the
attemptRefreshingSession
function and refresh it in the background. If there is no access token, or the refresh fails or ... It will follow the fallback by redirecting to a /session/refresh route that will refresh it again and either go to the /login route, or back to the previous route.
i
If possible I would love to see how your code works in action, i'm interested in implementing supertokens into a remix app as well, specifically a scenario where we have aseparate backend form the rmeix app
n
@iffa.dev I'll try to make a scoped demo repo this weekend or next week 👍
Longer term I'll try to wrap this in a package but I want to see what I'll tweak the coming weeks first.
i
Awesome! I’ll be waiting
@nudjialz any updates on this?
r
@iffa.dev we have an example app with remix that i can share tomorrow / day after. If i don't share it, please ping me here. Thanks!
@iffa.dev see this example repo for remix integration with supertokens please: https://github.com/mawentowski/supertokens_TPEP_remix
n
@iffa.dev I completely forgot about this, apologies!
Let me know if the repo shared above solves your questions, if not I can still look into making a demo repo myself (but you'll have to ping me again for this as well :D)
8 Views