refreshTokens when expired
I'm using Remix.js app, I've been trying to wrap my head around refreshTokens in Kinde and how to use it with remix.js.
Since remix doesn't have yet any auth middleware it's necessary for us to run requireAuthSession on loaders in all protected routes.
Could you please review my implementation, as I'm not sure it's correct.
1. First of all I check if user isAuthenticated, if this function returns false, then there is no point running token refresh. We just need to redirect user to login page.
2. Then we need to grab access_token. I shouldn't use
getToken
because this function automatically refresh tokens. I want existing cookie access_token, if it's expired I need to call refreshTokens and redirect to existing route with new headers (cookies).
Getting into cookies manually seems odd to me, but it seems like using getToken isn't really feasible if it doesn't return new Headers...
7 Replies
Hey @erich_fromm,
Thanks for reaching out.
Unfortunately I am not an expert in Remix, so I will have to reach out to my Remix team mate on this.
Hello Oli, did you get any update on this?
Hey @erich_fromm,
I will get an update for you on this by the end of the week.
Hey @erich_fromm, I made a new release of the remix sdk which fixes this issue 😄
Thanks @Peter (Kinde) , I've added one review comment
GitHub
Peter/fix refresh tokens by peterphanouvong · Pull Request #15 · ki...
Explain your changes
refresh tokens in the background
Suppose there is a related issue with enough detail for a reviewer to understand your changes fully. In that case, you can omit an explanation...
Thanks @erich_fromm
I'll just reply here - initially I had a check for the token expiry before calling refreshTokens like you had suggested but I was running into issues with that. I will need to take a deeper look into it next week. I think there is some condition in the TS SDK (which the Remix SDK is built on top of) that may be the cause of the weird behaviour.
That's why it has been released in its current state
But definielty something we want to address soon and optimise