From faf4c9fbe5abb91bef077c60dda70d7d4250ff9b Mon Sep 17 00:00:00 2001 From: Kyle McNally Date: Thu, 19 Dec 2024 02:34:27 -0500 Subject: [PATCH] chore(docs): update refresh-token-rotation.mdx (#12396) Update refresh-token-rotation.mdx Cleanup return when new access_token requested Co-authored-by: Nico Domino --- docs/pages/guides/refresh-token-rotation.mdx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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