fix: API 请求前用 keycloak.updateToken(30) 刷新即将过期的 token
GraphRAG CI/CD / build-and-deploy (push) Successful in 3m7s
GraphRAG CI/CD / build-and-deploy (push) Successful in 3m7s
getToken() 只返回缓存的 token,可能已过期(默认 5 分钟生命周期)。 updateToken(30) 确保发送前 token 至少还有 30 秒有效时长。
This commit is contained in:
@@ -32,11 +32,13 @@ async function request<T>(
|
||||
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> = {};
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user