21 lines
554 B
TypeScript
21 lines
554 B
TypeScript
import type { User, UserResponse } 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,
|
|
}
|
|
}
|