Issue with getKindeServerSession().refreshTokens(); in Next.js App Router
I am currently integrating Kinde with a Next.js application using the App Router. In my application, when a user logs in and successfully completes a payment transaction, I would like to set new properties for the user as paid user. However, I am encountering an issue when attempting to refresh the ID token using the method
getKindeServerSession().refreshTokens();
. It seems I am unable to fetch a new ID token after updating the user's properties.
Could you please provide guidance on how to resolve this issue or recommend an alternative approach for refreshing the ID token in this context?
Thank you!19 Replies
@Abel Trần sorry that you are seeing this issue. What version of the Next.js SDK are you using?
When you say you are unable to fetch a new ID token, are you getting an error or is the token coming back un updated?
@Andre @ Kinde
FYI, I am using:
"next": "14.2.4",
"@kinde-oss/kinde-auth-nextjs": "^2.3.8"
I don't see any error when I use await getKindeServerSession().refreshTokens();
, but the token does not change.Thanks for the details.
Able to update to v2.3.10?
When I update to v2.3.10, await getKindeServerSession().refreshTokens(); takes a long time to refresh, but the ID Token does not update.
Ok, thanks, I have passed this along to the team
Thank you! Please let me know if there's any further information or assistance I can provide to help with the investigation.
Hi @Abel Trần , just to confirm, these are user properties added to the id token through token customization, then updated via API?
Let me look into whether we should automatically invalid the cache in this case, in the mean time you can try making a call via the Management API to refresh the claims first using this API method: https://kinde.com/api/docs/#refresh-user-claims-and-invalidate-cache
I updated the user properties via API. After that, I tried calling the refresh token and even refreshing the user claims, but the token hasn't changed.
Here is the my sample code
Hi @Abel Trần ,
It looks like the cache should be updated automatically, so you shouldn't need to call the refresh_claims endpoint. After updating the properties via API, you can then call
refreshTokens()
to get the updated tokens.
Here is the code I used:
@leo_kinde
I tried
refreshTokens()
but my token does not change.
What can I do next?@Andre @ Kinde @leo_kinde
Can you help me check this again?
I successfully updated the value, but I cannot refresh to get the new values or token.
If I log out and log in again, I will receive the new value / token.
@Abel Trần , the
null
response from refreshTokens()
looks like there might be some error happening as it should return the new tokens. Can you set the environment variable KINDE_DEBUG_MODE
to true
and run it again and have a look to see if there are any errors logged?The refresh token is null when I use it in the middleware. However, when I use the server action, I can see the token, but it’s still the old one. I manually try to update
test_kinde_prop
in Kinde, but it seems undefined.Hey @Abel Trần,
Apologies for not getting back to you sooner.
We are still looking into this issue.
I update you, more regularly, as we progress in fixing this issue.
I updated to v2.3.11. It works well when I update properties via the API, but if I update them directly on the Kinde Dashboard, the data does not refresh.
Hey @Abel Trần,
This does not sound like the expected behaviour. I have let my team know this too.
Please continue to let us know of any other issues/findings you come across.
Yes, I will
Hey Abel what is the behaviour you're expecting on your app when data is updated on the Kinde dashboard?
I will try and recreate the server action experience you are having today
^ this is how to use refreshtoken in the server action to get the user to update
with the API
To see the updated user data, it will work automatically if you grab them from getKindeServerSession, but will need to force a reload (window.location.reload) for browserclient