From 58f3bf99dc2ef9c2cb57afea2365855f9b23d618 Mon Sep 17 00:00:00 2001 From: mtvpls Date: Tue, 27 Jan 2026 20:43:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=B7=E6=96=B0token?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E6=97=A0=E9=99=90=E9=87=8D=E5=AE=9A=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/db.client.ts | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/lib/db.client.ts b/src/lib/db.client.ts index 4d67aa2..3703572 100644 --- a/src/lib/db.client.ts +++ b/src/lib/db.client.ts @@ -527,6 +527,16 @@ async function fetchWithAuth( if (res.status === 401) { const text = await res.clone().text(); if (text === 'Access token expired') { + // 检查是否是登录相关的接口,如果是则不刷新 + if ( + url.includes('/api/login') || + url.includes('/api/register') || + url.includes('/api/auth/oidc') || + url.includes('/api/auth/refresh') + ) { + throw new Error('用户未授权'); + } + // 尝试刷新 token const refreshRes = await fetch('/api/auth/refresh', { method: 'POST', @@ -541,19 +551,22 @@ async function fetchWithAuth( // 如果刷新后仍然是 401,或者是其他 401 错误,跳转登录 if (res.status === 401) { - // 调用 logout 接口 - try { - await fetch('/api/logout', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - }); - } catch (error) { - console.error('注销请求失败:', error); + // 检查当前页面是否已经是登录页,避免重复跳转 + if (typeof window !== 'undefined' && !window.location.pathname.startsWith('/login')) { + // 调用 logout 接口 + try { + await fetch('/api/logout', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + }); + } catch (error) { + console.error('注销请求失败:', error); + } + const currentUrl = window.location.pathname + window.location.search; + const loginUrl = new URL('/login', window.location.origin); + loginUrl.searchParams.set('redirect', currentUrl); + window.location.href = loginUrl.toString(); } - const currentUrl = window.location.pathname + window.location.search; - const loginUrl = new URL('/login', window.location.origin); - loginUrl.searchParams.set('redirect', currentUrl); - window.location.href = loginUrl.toString(); throw new Error('用户未授权,已跳转到登录页面'); } } From 943efe9269b6cf627d3f0e814324e8f96a9ee6be Mon Sep 17 00:00:00 2001 From: mtvpls Date: Tue, 27 Jan 2026 21:38:17 +0800 Subject: [PATCH 2/2] v21012 --- CHANGELOG | 6 +++++- VERSION.txt | 2 +- src/lib/changelog.ts | 10 ++++++++++ src/lib/version.ts | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0f54ed5..d7bc1ec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,8 @@ -## [210.1.0] - 2026-01-27 +## [210.1.2] - 2026-01-27 +### Fixed +- 修复刷新token失效无限重定向 + +## [210.1.1] - 2026-01-27 ### Fixed - 修复token过期重定向无法续期的问题 diff --git a/VERSION.txt b/VERSION.txt index e8e6a37..bdea846 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1,2 +1,2 @@ -210.1.1 +210.1.2 diff --git a/src/lib/changelog.ts b/src/lib/changelog.ts index 0a240c9..977d26e 100644 --- a/src/lib/changelog.ts +++ b/src/lib/changelog.ts @@ -11,6 +11,16 @@ export interface ChangelogEntry { export const changelog: ChangelogEntry[] = [ { + version: '210.1.2', + date: '2026-01-27', + added: [ + ], + changed: [ + ], + fixed: [ + "修复刷新token失效无限重定向" + ] + },{ version: '210.1.1', date: '2026-01-27', added: [ diff --git a/src/lib/version.ts b/src/lib/version.ts index 112e9af..c8fef0c 100644 --- a/src/lib/version.ts +++ b/src/lib/version.ts @@ -1,6 +1,6 @@ /* eslint-disable no-console */ -const CURRENT_VERSION = '210.1.1'; +const CURRENT_VERSION = '210.1.2'; // 导出当前版本号供其他地方使用 export { CURRENT_VERSION };