Welcome to the Kinde community.

P
K
A
A
A

Nextjs app router sdk not automatically refreshing access token when it expires

Hello, we are trying to integrate NextJS App router SDK in our nextjs application (nextjs version -> 14.2.7, @kinde-oss/kinde-auth-nextjs -> 2.3.8)
when our access_token expires, the SDK does not automatically fetch the new access token using our refresh token (which is not expired yet!), and when we use the method isAuthenticated(), it also returns true, even if the access token is expired.
does anybody have any suggestions to fix this?

2
P
M
L
16 comments

Hey ,
Sorry that you are experiencing this issue.

Are you able to update to the latest NextJS SDK v2.3.10 and let me know if you are still experiencing this issue?

sure, let me try.

no, it is not solving the issue.

it is showing me the user is authenticated, whereas the token is expired. it is also not replacing it with new token with the help of refresh token
cc:

Hey ,
Sorry to hear that this did not fix your issue.
I am discussing this issue with my team.

I will get back to you once I have an update on this issue.

Hi , I’m not able to reproduce this. Can you provide some information about how you are testing this and how you have determined the token has expired?


we are determining the token expiration by looking at the field exp
the token has exp in past, and when we check the authentication using the method isAuthenticated() (which is imported from getKindeServerSession()). Note that, we are using it inside our middleware file, which is part of pages router, while the sdk which we are using is of app router.
and to be precise, the middleware file lies at src/middleware.ts and the pages router lies at src/pages

Please let me know, if you need further information in this structure. Also, the versions of nextjs is mentioned in the start of the thread. the kinde sdk version is up to date to 2.3.10 as suggested by Oli (your team member)

can u help plz?

Hey ,
I will speak to Leo about this tomorrow.
Sorry for not getting back to you earlier.

Hey ,
We are going to give this issue more attention early next week.
I will continue to update you as we progress with solving your issue - apologies again.

thanks looking forward to getting the solution

can you folks confirm, is it reproducible at your side?

Hey ,
I will pass on an update from my team to you tomorrow.

hi folks! I'm pretty new to Kinde, and found this thread on Google. I'm just testing it out locally at the moment, but I just got an error where isAuthenticated is true, but the access token has expired. Is this expected behavior, or is the Nextjs SDK supposed to automatically refresh all tokens?

fwiw this happens both in local dev, and in our production environment (Vercel)

as mentioned above, in a server component await getKindeServerSession().isAuthenticated() is true, but if I manually check the access token with await getKindeServerSession().getAccessTokenRaw(), the expired field tells me that the token has, well, expired 🙂

Add a reply
Sign up and join the conversation on Slack
Join