@@ -45,10 +45,10 @@ export default Auth(new Request("https://example.com"), {
45
45
// Save the access token and refresh token in the JWT on the initial login
46
46
return {
47
47
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 ) ,
49
49
refresh_token: account .refresh_token ,
50
50
}
51
- } else if (Date .now () < token .expires_at ) {
51
+ } else if (Date .now () < token .expires_at * 1000 ) {
52
52
// If the access token has not expired yet, return it
53
53
return token
54
54
} else {
@@ -74,7 +74,7 @@ export default Auth(new Request("https://example.com"), {
74
74
return {
75
75
... token , // Keep the previous token properties
76
76
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 ) ,
78
78
// Fall back to old refresh token, but note that
79
79
// many providers may only allow using a refresh token once.
80
80
refresh_token: tokens .refresh_token ?? token .refresh_token ,
@@ -136,7 +136,7 @@ export default Auth(new Request("https://example.com"), {
136
136
const [google] = await prisma .account .findMany ({
137
137
where: { userId: user .id , provider: " google" },
138
138
})
139
- if (google .expires_at < Date .now ()) {
139
+ if (google .expires_at * 1000 < Date .now ()) {
140
140
// If the access token has expired, try to refresh it
141
141
try {
142
142
// https://accounts.google.com/.well-known/openid-configuration
@@ -159,7 +159,7 @@ export default Auth(new Request("https://example.com"), {
159
159
await prisma .account .update ({
160
160
data: {
161
161
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 ) ,
163
163
refresh_token: tokens .refresh_token ?? google .refresh_token ,
164
164
},
165
165
where: {
0 commit comments