fix: API 请求前用 keycloak.updateToken(30) 刷新即将过期的 token
GraphRAG CI/CD / build-and-deploy (push) Successful in 3m7s

getToken() 只返回缓存的 token,可能已过期(默认 5 分钟生命周期)。
updateToken(30) 确保发送前 token 至少还有 30 秒有效时长。
This commit is contained in:
2026-06-18 16:02:07 +08:00
parent e49b01ddd4
commit d2f782e47e
+5 -3
View File
@@ -32,11 +32,13 @@ async function request<T>(
if (parts.length) url += '?' + parts.join('&'); 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<string, string> = {}; const headers: Record<string, string> = {};
try { try {
const { getToken } = await import('./auth'); const mod = await import('./auth');
const token = getToken(); // 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}`; if (token) headers['Authorization'] = `Bearer ${token}`;
} catch { /* auth not initialized */ } } catch { /* auth not initialized */ }
if (!options.formData && options.body !== undefined) { if (!options.formData && options.body !== undefined) {