From b4276f58b25109b45b4be523edfc4ccb3f8d073c Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Tue, 4 Nov 2025 09:54:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20=E4=BF=AE=E5=A4=8Dtoken=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=A4=B1=E8=B4=A5=E6=97=B6=E8=AF=B7=E6=B1=82=E6=B3=84?= =?UTF-8?q?=E6=BC=8F=E5=AF=BC=E8=87=B4=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/auth/useTokenRefresh.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/composables/auth/useTokenRefresh.ts b/src/composables/auth/useTokenRefresh.ts index c81be723..12e138e6 100644 --- a/src/composables/auth/useTokenRefresh.ts +++ b/src/composables/auth/useTokenRefresh.ts @@ -55,13 +55,17 @@ export function useTokenRefresh() { }) .catch(async (error) => { console.error("Token refresh failed:", error); - // 刷新失败,清空队列并跳转登录页 + // 刷新失败,先 reject 所有等待的请求,再清空队列 + const failedRequests = [...pendingRequests]; pendingRequests.length = 0; - await redirectToLogin("登录状态已失效,请重新登录"); + // 拒绝所有等待的请求 - pendingRequests.forEach(() => { + failedRequests.forEach(() => { reject(new Error("Token refresh failed")); }); + + // 跳转登录页 + await redirectToLogin("登录状态已失效,请重新登录"); }) .finally(() => { isRefreshingToken = false;