diff --git a/frontend/src/app/api.ts b/frontend/src/app/api.ts index 20da8f6..0074de9 100644 --- a/frontend/src/app/api.ts +++ b/frontend/src/app/api.ts @@ -32,11 +32,13 @@ async function request( if (parts.length) url += '?' + parts.join('&'); } - // Build headers with optional Bearer token + // Build headers with optional Bearer token — refresh if near expiry const headers: Record = {}; try { - const { getToken } = await import('./auth'); - const token = getToken(); + const mod = await import('./auth'); + // Ensure token is valid for at least 30s before sending + await mod.default.updateToken(30); + const token = mod.getToken(); if (token) headers['Authorization'] = `Bearer ${token}`; } catch { /* auth not initialized */ } if (!options.formData && options.body !== undefined) {