Update access_token and refresh_token with a new access_token and refresh_token #4683
Replies: 5 comments 1 reply
-
@dephraiim this article should help: https://next-auth.js.org/tutorials/refresh-token-rotation |
Beta Was this translation helpful? Give feedback.
-
Hello @Miciurash, I tried this. It didn't work. Maybe I'm missing something. Let me check again. |
Beta Was this translation helpful? Give feedback.
-
I also tried implementing a solution by following the refresh-token-rotation tutorial and found that it doesn't actually update the JWT itself. When the session is expired, it only returns a new token to the session callback without updating the access token and expiration in the JWT. This results in the From the tutorial...// Return previous token if the access token has not expired yet
if (Date.now() < token.accessTokenExpires) {
return token
}
// Access token has expired, try to update it
return refreshAccessToken(token) // ‼️ This will always happen after the access token expired because it is never actually updated Perhaps the author of the tutorial missed the step to update the JWT with the new access token and expiration date (if that was the intended behavior). In my own implementation, I'm using a custom CredentialsProvider, which has a session token that expires after 24 hours. If the token is expired, I want to update the session token and expiration in the JWT (or replace it if needed). EDIT: Still digging into this, but this long discussion is related and looks to have hit a dead end last year #3940 |
Beta Was this translation helpful? Give feedback.
-
Just popping here for the updates |
Beta Was this translation helpful? Give feedback.
-
➕ Same I've made an issue with more details #5348 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Question 💬
I am using
access_token
from the Twitter API. It has a limit of 2 hours so I am using therefresh_token
to get a newaccess_token
. How do I update the originalaccess_token
from Twitter to use the newaccess_token
I had.PS: I am not using a Database. I am also fetching the new
access_token
from an API endpoint.How to reproduce ☕️
next-auth-example
, fetch anaccess_token
using any provideraccess_token
expires, use therefresh_token
to fetch a newaccess_token
token
from thegetToken
function with the newaccess_token
Contributing 🙌🏽
Yes, I am willing to help answer this question in a PR
Beta Was this translation helpful? Give feedback.
All reactions