Skip to content

Commit 8b38d32

Browse files
docs: update refresh token guide
closes #6696
1 parent 1e5f840 commit 8b38d32

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/docs/guides/03-basics/refresh-token-rotation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ export default Auth(new Request("https://example.com"), {
4545
// Save the access token and refresh token in the JWT on the initial login
4646
return {
4747
access_token: account.access_token,
48-
expires_at: Date.now() + account.expires_in * 1000,
48+
expires_at: Math.floor(Date.now() / 1000 + account.expires_in),
4949
refresh_token: account.refresh_token,
5050
}
51-
} else if (Date.now() < token.expires_at) {
51+
} else if (Date.now() < token.expires_at * 1000) {
5252
// If the access token has not expired yet, return it
5353
return token
5454
} else {
@@ -74,7 +74,7 @@ export default Auth(new Request("https://example.com"), {
7474
return {
7575
...token, // Keep the previous token properties
7676
access_token: tokens.access_token,
77-
expires_at: Date.now() + tokens.expires_in * 1000,
77+
expires_at: Math.floor(Date.now() / 1000 + tokens.expires_in),
7878
// Fall back to old refresh token, but note that
7979
// many providers may only allow using a refresh token once.
8080
refresh_token: tokens.refresh_token ?? token.refresh_token,
@@ -136,7 +136,7 @@ export default Auth(new Request("https://example.com"), {
136136
const [google] = await prisma.account.findMany({
137137
where: { userId: user.id, provider: "google" },
138138
})
139-
if (google.expires_at < Date.now()) {
139+
if (google.expires_at * 1000 < Date.now()) {
140140
// If the access token has expired, try to refresh it
141141
try {
142142
// https://accounts.google.com/.well-known/openid-configuration
@@ -159,7 +159,7 @@ export default Auth(new Request("https://example.com"), {
159159
await prisma.account.update({
160160
data: {
161161
access_token: tokens.access_token,
162-
expires_at: Date.now() + tokens.expires_in * 1000,
162+
expires_at: Math.floor(Date.now() / 1000 + tokens.expires_in),
163163
refresh_token: tokens.refresh_token ?? google.refresh_token,
164164
},
165165
where: {

0 commit comments

Comments
 (0)