Skip to content

Commit 2c52e0d

Browse files
committed
Small tweak -- move 'now' to where it's used.
Since the token exchange callback could take non-negligible time, this is more correct, and anyway it's easier to read.
1 parent 38295b6 commit 2c52e0d

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/oauth-provider.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,8 +1234,6 @@ class OAuthProviderImpl {
12341234
const accessTokenId = await generateTokenId(accessToken);
12351235
const refreshTokenId = await generateTokenId(refreshToken);
12361236

1237-
const now = Math.floor(Date.now() / 1000);
1238-
12391237
// Define the access token TTL, may be updated by callback if provided
12401238
let accessTokenTTL = this.options.accessTokenTTL!;
12411239

@@ -1307,6 +1305,7 @@ class OAuthProviderImpl {
13071305
}
13081306

13091307
// Calculate the access token expiration time (after callback might have updated TTL)
1308+
const now = Math.floor(Date.now() / 1000);
13101309
const accessTokenExpiresAt = now + accessTokenTTL;
13111310

13121311
// Wrap the keys for the new tokens
@@ -1441,8 +1440,6 @@ class OAuthProviderImpl {
14411440
const newRefreshToken = `${userId}:${grantId}:${refreshTokenSecret}`;
14421441
const newRefreshTokenId = await generateTokenId(newRefreshToken);
14431442

1444-
const now = Math.floor(Date.now() / 1000);
1445-
14461443
// Define the access token TTL, may be updated by callback if provided
14471444
let accessTokenTTL = this.options.accessTokenTTL!;
14481445

@@ -1534,6 +1531,7 @@ class OAuthProviderImpl {
15341531
}
15351532

15361533
// Calculate the access token expiration time (after callback might have updated TTL)
1534+
const now = Math.floor(Date.now() / 1000);
15371535
const accessTokenExpiresAt = now + accessTokenTTL;
15381536

15391537
// Wrap the key for both the new access token and refresh token

0 commit comments

Comments
 (0)