import apiClient from "../client" import type { User, UserResponse, UpdateProfileRequest, UpdateProfileResponse } from "./types" /** * 规范化用户数据,兼容不同后端返回格式 */ export const normalizeUser = (data: UserResponse): User => { const userId = data.id ?? data.user_id ?? "" const emailVerified = data.is_email_verified ?? data.email_verified ?? false return { id: userId, user_id: userId, email: data.email, username: data.username, display_name: data.display_name, is_email_verified: emailVerified, email_verified: emailVerified, created_at: data.created_at, wechat_bound: data.wechat_bound, wechat_nickname: data.wechat_nickname, avatar_url: data.avatar_url, phone: data.phone, phone_verified: data.phone_verified, profile_completed: data.profile_completed, } } /** * 更新个人资料(昵称等) */ export const updateProfile = async (data: UpdateProfileRequest): Promise => { const response = await apiClient.patch("/auth/me", data) return normalizeUser(response.data.user) }