From 48ed7970554af522dae847de7b6a92bb26d1cb0c Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 9 Jan 2026 22:38:11 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E9=98=B2=E6=AD=A2=20/logout=20?= =?UTF-8?q?=E6=AD=BB=E5=BE=AA=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/src/store/auth.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/playground/src/store/auth.ts b/playground/src/store/auth.ts index 4adeb76e1..9d461d153 100644 --- a/playground/src/store/auth.ts +++ b/playground/src/store/auth.ts @@ -78,11 +78,17 @@ export const useAuthStore = defineStore('auth', () => { }; } + let isLoggingOut = false; // 正在 logout 标识, 防止 /logout 死循环. + async function logout(redirect: boolean = true) { + if (isLoggingOut) return; + isLoggingOut = true; try { await logoutApi(); } catch { // 不做任何处理 + } finally { + isLoggingOut = false; } resetAllStores(); From 13c8318adc5aa28cb90cc55d1de9eb7ba1ae14cc Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 9 Jan 2026 23:05:05 +0800 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=201.=20=E7=94=A8=20ref=20?= =?UTF-8?q?=E5=8C=85=E8=A3=85=20flag;=202.=20=E5=9C=A8=E6=9C=80=E5=90=8E?= =?UTF-8?q?=20=E6=B8=85=E7=90=86=20flag;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/src/store/auth.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/playground/src/store/auth.ts b/playground/src/store/auth.ts index 9d461d153..1fec5c049 100644 --- a/playground/src/store/auth.ts +++ b/playground/src/store/auth.ts @@ -78,31 +78,32 @@ export const useAuthStore = defineStore('auth', () => { }; } - let isLoggingOut = false; // 正在 logout 标识, 防止 /logout 死循环. + const isLoggingOut = ref(false); // 正在 logout 标识, 防止 /logout 死循环. async function logout(redirect: boolean = true) { - if (isLoggingOut) return; - isLoggingOut = true; + if (isLoggingOut.value) return; // 正在登出中, 说明已进入循环, 直接返回. + isLoggingOut.value = true; // 设置 标识 + try { await logoutApi(); + + resetAllStores(); + accessStore.setLoginExpired(false); + + // 回登录页带上当前路由地址 + await router.replace({ + path: LOGIN_PATH, + query: redirect + ? { + redirect: encodeURIComponent(router.currentRoute.value.fullPath), + } + : {}, + }); } catch { // 不做任何处理 } finally { - isLoggingOut = false; + isLoggingOut.value = false; // 重置 标识 } - - resetAllStores(); - accessStore.setLoginExpired(false); - - // 回登录页带上当前路由地址 - await router.replace({ - path: LOGIN_PATH, - query: redirect - ? { - redirect: encodeURIComponent(router.currentRoute.value.fullPath), - } - : {}, - }); } async function fetchUserInfo() { From 1cb53e943ea99acb655100dcfaf743b01de1a09a Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 9 Jan 2026 23:13:06 +0800 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=E5=B0=86=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E6=94=BE=E5=88=B0=E6=9C=80=E5=90=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/src/store/auth.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/playground/src/store/auth.ts b/playground/src/store/auth.ts index 1fec5c049..14100727d 100644 --- a/playground/src/store/auth.ts +++ b/playground/src/store/auth.ts @@ -89,21 +89,21 @@ export const useAuthStore = defineStore('auth', () => { resetAllStores(); accessStore.setLoginExpired(false); - - // 回登录页带上当前路由地址 - await router.replace({ - path: LOGIN_PATH, - query: redirect - ? { - redirect: encodeURIComponent(router.currentRoute.value.fullPath), - } - : {}, - }); } catch { // 不做任何处理 } finally { isLoggingOut.value = false; // 重置 标识 } + + // 回登录页带上当前路由地址 + await router.replace({ + path: LOGIN_PATH, + query: redirect + ? { + redirect: encodeURIComponent(router.currentRoute.value.fullPath), + } + : {}, + }); } async function fetchUserInfo() { From 694396dcfb187595888100b7df676582b11a02e7 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 9 Jan 2026 23:22:49 +0800 Subject: [PATCH 4/4] refactor: move cleanup to finally block --- playground/src/store/auth.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/playground/src/store/auth.ts b/playground/src/store/auth.ts index 14100727d..b50ee7729 100644 --- a/playground/src/store/auth.ts +++ b/playground/src/store/auth.ts @@ -86,13 +86,13 @@ export const useAuthStore = defineStore('auth', () => { try { await logoutApi(); - - resetAllStores(); - accessStore.setLoginExpired(false); } catch { // 不做任何处理 } finally { isLoggingOut.value = false; // 重置 标识 + + resetAllStores(); + accessStore.setLoginExpired(false); } // 回登录页带上当前路由地址