diff --git a/docs/pages/guides/refresh-token-rotation.mdx b/docs/pages/guides/refresh-token-rotation.mdx index b00be118ad..b8215cd205 100644 --- a/docs/pages/guides/refresh-token-rotation.mdx +++ b/docs/pages/guides/refresh-token-rotation.mdx @@ -102,14 +102,15 @@ export const { handlers, auth } = NextAuth({ refresh_token?: string } - token.access_token = newTokens.access_token - token.expires_at = Math.floor( - Date.now() / 1000 + newTokens.expires_in - ) - // Some providers only issue refresh tokens once, so preserve if we did not get a new one - if (newTokens.refresh_token) - token.refresh_token = newTokens.refresh_token - return token + return { + ...token, + access_token: newTokens.access_token, + expires_at: Math.floor( + Date.now() / 1000 + newTokens.expires_in + ), + // Some providers only issue refresh tokens once, so preserve if we did not get a new one + refresh_token: newTokens.refresh_token ? newTokens.refresh_token : token.refresh_token + } } catch (error) { console.error("Error refreshing access_token", error) // If we fail to refresh the token, return an error so we can handle it on the page