From 99e1e308a0e4223ac6ad00bf065811ef44946427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kalle=20Ahlstr=C3=B6m?= Date: Sat, 27 May 2023 04:56:25 -0700 Subject: [PATCH] move login renew threshold to a variable --- packages/ilmomasiina-frontend/src/api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ilmomasiina-frontend/src/api.ts b/packages/ilmomasiina-frontend/src/api.ts index 48735b3f..50b3abf4 100644 --- a/packages/ilmomasiina-frontend/src/api.ts +++ b/packages/ilmomasiina-frontend/src/api.ts @@ -7,7 +7,7 @@ import type { DispatchAction } from './store/types'; interface AdminApiFetchOptions extends FetchOptions { accessToken?: AccessToken; } - +const RENEW_LOGIN_THRESHOLD = 5 * 60 * 1000; /** Wrapper for apiFetch that checks for Unauthenticated responses and dispatches a loginExpired * action if necessary. */ @@ -18,7 +18,7 @@ export default async function adminApiFetch(uri: string, opts: AdminApi if (!accessToken) { throw new ApiError(401, { isUnauthenticated: true }); } - if (!(accessToken.expiresAt < Date.now() - 4 * 60 * 1000)) { + if (!(accessToken.expiresAt < Date.now() - RENEW_LOGIN_THRESHOLD)) { await dispatch(renewLogin(accessToken.token)); } return await apiFetch(uri, { ...opts, headers: { ...opts.headers, Authorization: accessToken.token } });