From e4b249f5024f974ad9a26ae9aecb4d714dd7670e Mon Sep 17 00:00:00 2001 From: imeepos Date: Fri, 23 Jan 2026 19:28:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BD=93=E5=89=8D=E7=99=BB=E5=BD=95=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=9A=84=E7=9C=9F=E5=AE=9E=E7=94=A8=E6=88=B7=E5=90=8D?= =?UTF-8?q?=E5=92=8CID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 useSession hook 获取当前登录用户信息 - 用户名从 session.user.name 或 session.user.username 获取 - 用户ID显示真实用户ID的前8位 - 添加 useEffect 监听 session 变化自动更新 修复前:显示硬编码的 "乔乔乔乔" 和 "ID 12345678" 修复后:显示当前登录用户的真实信息 Co-Authored-By: Claude --- app/(tabs)/my.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/(tabs)/my.tsx b/app/(tabs)/my.tsx index fc1a6b0..ca70c7f 100644 --- a/app/(tabs)/my.tsx +++ b/app/(tabs)/my.tsx @@ -20,6 +20,7 @@ import Toast from '@/components/ui/Toast' import { signOut } from '@/lib/auth' import { useTemplateGenerations, type TemplateGeneration } from '@/hooks' import { MySkeleton } from '@/components/skeleton/MySkeleton' +import { useSession } from '@/lib/auth' const { width: screenWidth } = Dimensions.get('window') const GALLERY_GAP = 2 @@ -36,7 +37,18 @@ export default function My() { const router = useRouter() const { t, i18n } = useTranslation() const [editDrawerVisible, setEditDrawerVisible] = useState(false) - const [profileName, setProfileName] = useState('乔乔乔乔') + + // 获取当前登录用户信息 + const { data: session } = useSession() + const userName = session?.user?.name || session?.user?.username || '用户' + const [profileName, setProfileName] = useState(userName) + + // 当 session 变化时更新用户名 + useEffect(() => { + if (session?.user?.name || session?.user?.username) { + setProfileName(session?.user?.name || session?.user?.username || '用户') + } + }, [session]) // 使用 useTemplateGenerations hook 获取用户作品列表 const { @@ -148,7 +160,7 @@ export default function My() { /> {profileName} - ID 12345678 + ID {session?.user?.id?.slice(0, 8) || '--------'}