From deb96400919540b3c8fbb1d89f6eefe89d715b09 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 2 Jul 2022 20:55:59 +0100 Subject: Base refresh timeout on diff from current time Previously the logic was using the expiry date's unix timestamp as if it was a number of ms until it expired. This caused the timeout to be far after the actual token expiry. --- src/api/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/api/auth.ts b/src/api/auth.ts index 7f01b9d..de6210e 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -204,7 +204,7 @@ export async function refreshBackendJWT(): Promise { cookies.set(CookieNames.Username, response.data.username, {sameSite: "strict", secure: PRODUCTION, path: "/", expires: new Date(3000, 1)}); const expiry = Date.parse(response.data.expiry); - setTimeout(refreshBackendJWT, (expiry * 0.9)); + setTimeout(refreshBackendJWT, ((expiry - Date.now()) / 1000 * 0.9)); }).catch(() => { pass = false; cookies.remove(CookieNames.Scopes); -- cgit v1.2.3