From 7ab899b44fed7a542378880a63d258d516cbe407 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 4 May 2026 09:12:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20JWT=E5=AF=86=E9=92=A5YAML=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=92=8C401=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复JWT密钥在YAML配置文件中未加引号导致解析错误的问题 - 添加dashboard页面401错误处理,自动清除token并跳转登录页 --- backend/internal/router/install/install.go | 2 +- frontend/src/pages/admin/index.vue | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/internal/router/install/install.go b/backend/internal/router/install/install.go index 28899fb..8f608dd 100644 --- a/backend/internal/router/install/install.go +++ b/backend/internal/router/install/install.go @@ -299,7 +299,7 @@ func generateConfigFile(dbType string, req SetupRequest, jwtSecret string) strin content.WriteString(" name: verification-platform\n") content.WriteString(" env: production\n") content.WriteString(" port: \"8080\"\n") - content.WriteString(fmt.Sprintf(" jwt_secret: %s\n", jwtSecret)) + content.WriteString(fmt.Sprintf(" jwt_secret: \"%s\"\n", jwtSecret)) content.WriteString(" jwt_expire: 24h\n\n") content.WriteString("# 数据库配置\n") diff --git a/frontend/src/pages/admin/index.vue b/frontend/src/pages/admin/index.vue index 9c855c5..972914a 100644 --- a/frontend/src/pages/admin/index.vue +++ b/frontend/src/pages/admin/index.vue @@ -145,6 +145,7 @@ async function fetchDashboard() { const token = localStorage.getItem('token') if (!token) { console.error('No token found') + router.push('/login') return } @@ -154,6 +155,13 @@ async function fetchDashboard() { }, }) + if (response.status === 401) { + localStorage.removeItem('token') + localStorage.removeItem('user') + router.push('/login') + return + } + if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`) }