fix: 个人中心显示当前登录用户的真实用户名和ID

- 使用 useSession hook 获取当前登录用户信息
- 用户名从 session.user.name 或 session.user.username 获取
- 用户ID显示真实用户ID的前8位
- 添加 useEffect 监听 session 变化自动更新

修复前:显示硬编码的 "乔乔乔乔" 和 "ID 12345678"
修复后:显示当前登录用户的真实信息

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
imeepos 2026-01-23 19:28:41 +08:00
parent 7d160d55ea
commit e4b249f502
1 changed files with 14 additions and 2 deletions

View File

@ -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() {
/>
<View style={styles.profileInfo}>
<Text style={styles.profileName}>{profileName}</Text>
<Text style={styles.profileSubTitle}>ID 12345678</Text>
<Text style={styles.profileSubTitle}>ID {session?.user?.id?.slice(0, 8) || '--------'}</Text>
</View>
<Pressable
style={styles.editButton}