From c6a7889b43627ae9b46725b22db311c26c527124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=B7=E9=BE=99?= Date: Thu, 28 Aug 2025 22:39:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/auth/auth-guard.tsx | 8 +++----- components/layout/top-bar.tsx | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/components/auth/auth-guard.tsx b/components/auth/auth-guard.tsx index 4430fbb..24b96af 100644 --- a/components/auth/auth-guard.tsx +++ b/components/auth/auth-guard.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'; import { useRouter, usePathname } from 'next/navigation'; -import { checkAuth, isAuthenticated } from '@/lib/auth'; +import { checkAuth, getUserProfile, isAuthenticated } from '@/lib/auth'; import GlobalLoad from '../common/GlobalLoad'; interface AuthGuardProps { @@ -36,12 +36,10 @@ export default function AuthGuard({ children }: AuthGuardProps) { try { // 调用鉴权接口验证token - const isValid = await checkAuth(); - - if (isValid) { + const user = await getUserProfile(); + if (user) { setIsAuthorized(true); } else { - // Token无效,重定向到登录页 router.push('/login'); } } catch (error) { diff --git a/components/layout/top-bar.tsx b/components/layout/top-bar.tsx index f003157..0508606 100644 --- a/components/layout/top-bar.tsx +++ b/components/layout/top-bar.tsx @@ -268,8 +268,8 @@ export function TopBar({ {/* User Info */}
-
- {currentUser.name ? currentUser.name.charAt(0) : ""} +
+ MF