K
Kinde4mo ago
Jumper

How to detect if a token has expired with the Client JS SDK?

Hi all, Just wondering how to detect if a token has expired on the front-end so I can refresh it? When the token expires I can no longer use KindeClient.getIdToken so I can't check on the token itself?
3 Replies
Oli - Kinde
Oli - Kinde4mo ago
Hey @Jumper, To detect if a token has expired on the front-end and refresh it when using Kinde, you typically don't need to manually check for token expiration. The Kinde front-end SDKs, such as the JavaScript SDK or React SDK, handle this automatically. The getToken function provided by these SDKs manages an in-memory cache of the access token and automatically uses a refresh token to obtain a new access token from Kinde silently in the background when the current token is about to expire. This process ensures that additional network requests to Kinde are only made when absolutely necessary. What SDK are you using?
Jumper
Jumper4mo ago
Hey! This is using the @kinde-oss/kinde-auth-pkce-js package. And well basically when you call createKindeClient it will throw an error if the token is expired... So ok, I could catch the error and then redirect them back to kinde's site to refresh their token... But it doesn't feel particularly robust
Oli - Kinde
Oli - Kinde4mo ago
Hey @Jumper, Sounds odd that the token is not refreshed when using @kinde-oss/kinde-auth-pkce-js package. I will reach out to a member of my team tomorrow who is more faimiliar with the JavaScript SDK to help you out.
So ok, I could catch the error and then redirect them back to kinde's site to refresh their token... But it doesn't feel particularly robust
This is far from an ideal approach, as stated the JS SDK should automatically refresh the token. Let me get back to you on this
Want results from more Discord servers?
Add your server