Skip to content

Commit 3c514f9

Browse files
1423 Introduces getCurrentDateInSeconds function to be reused
1 parent 6f33c19 commit 3c514f9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pages/api/auth/[...nextauth].ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ const token_endpoint_auth_method = OAUTH2_CLIENT_SECRET
3232
? 'client_secret_basic'
3333
: 'none';
3434

35+
const getCurrentDateInSeconds = () => Math.floor(Date.now() / 1000);
36+
3537
const calculateExpirationDate = (expiresIn?: number) => {
3638
if (!expiresIn) {
3739
return undefined;
3840
}
3941

40-
return Math.floor(Date.now() / 1000) + expiresIn;
42+
return getCurrentDateInSeconds() + expiresIn;
4143
};
4244
const getWellKnownData = async () => {
4345
const wellKnownUrl = new URL(OIDC_CONF_FULL_WELL_KNOWN_URL);
@@ -150,7 +152,7 @@ export const authOptions: AuthOptions = {
150152
};
151153
}
152154

153-
const now = Math.floor(Date.now() / 1000);
155+
const now = getCurrentDateInSeconds();
154156
if (
155157
typeof token.accessTokenExpiresAt === 'number' &&
156158
now < token.accessTokenExpiresAt

0 commit comments

Comments
 (0)