Skip to content

Commit

Permalink
1423 Introduces getCurrentDateInSeconds function to be reused
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardovdheijden committed Sep 27, 2024
1 parent 6f33c19 commit 3c514f9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ const token_endpoint_auth_method = OAUTH2_CLIENT_SECRET
? 'client_secret_basic'
: 'none';

const getCurrentDateInSeconds = () => Math.floor(Date.now() / 1000);

const calculateExpirationDate = (expiresIn?: number) => {
if (!expiresIn) {
return undefined;
}

return Math.floor(Date.now() / 1000) + expiresIn;
return getCurrentDateInSeconds() + expiresIn;
};
const getWellKnownData = async () => {
const wellKnownUrl = new URL(OIDC_CONF_FULL_WELL_KNOWN_URL);
Expand Down Expand Up @@ -150,7 +152,7 @@ export const authOptions: AuthOptions = {
};
}

const now = Math.floor(Date.now() / 1000);
const now = getCurrentDateInSeconds();
if (
typeof token.accessTokenExpiresAt === 'number' &&
now < token.accessTokenExpiresAt
Expand Down

0 comments on commit 3c514f9

Please sign in to comment.