Skip to content

Commit

Permalink
move login renew threshold to a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kahlstrm authored and PurkkaKoodari committed Mar 7, 2024
1 parent dcd85a7 commit 99e1e30
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/ilmomasiina-frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -18,7 +18,7 @@ export default async function adminApiFetch<T = any>(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<T>(uri, { ...opts, headers: { ...opts.headers, Authorization: accessToken.token } });
Expand Down

0 comments on commit 99e1e30

Please sign in to comment.