From e56a8209e13dc1200273e2987c6caecea2a2c44b Mon Sep 17 00:00:00 2001 From: JackEnx Date: Wed, 19 Jun 2024 20:21:50 -0300 Subject: [PATCH] fix: refresh session token --- src/main/services/hydra-api.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index f8361260..31e69a8f 100644 --- a/src/main/services/hydra-api.ts +++ b/src/main/services/hydra-api.ts @@ -8,6 +8,8 @@ export class HydraApi { private static readonly EXPIRATION_OFFSET_IN_MS = 1000 * 60 * 5; + private static secondsToMilliseconds = (seconds: number) => seconds * 1000; + private static userAuth = { authToken: "", refreshToken: "", @@ -29,7 +31,9 @@ export class HydraApi { const now = new Date(); const tokenExpirationTimestamp = - now.getTime() + expiresIn - this.EXPIRATION_OFFSET_IN_MS; + now.getTime() + + this.secondsToMilliseconds(expiresIn) - + this.EXPIRATION_OFFSET_IN_MS; this.userAuth = { authToken: accessToken, @@ -110,7 +114,9 @@ export class HydraApi { const { accessToken, expiresIn } = response.data; const tokenExpirationTimestamp = - now.getTime() + expiresIn - this.EXPIRATION_OFFSET_IN_MS; + now.getTime() + + this.secondsToMilliseconds(expiresIn) - + this.EXPIRATION_OFFSET_IN_MS; this.userAuth.authToken = accessToken; this.userAuth.expirationTimestamp = tokenExpirationTimestamp;