Skip to content

Commit

Permalink
chore(docs): update refresh-token-rotation.mdx (#12396)
Browse files Browse the repository at this point in the history
Update refresh-token-rotation.mdx

Cleanup return when new access_token requested

Co-authored-by: Nico Domino <[email protected]>
  • Loading branch information
Sparticuz and ndom91 authored Dec 19, 2024
1 parent ddcdf9f commit faf4c9f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions docs/pages/guides/refresh-token-rotation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit faf4c9f

Please sign in to comment.