- 更新 DashboardLayout 组件,统一使用演示模式布局 - 实现仪表盘页面的完整演示数据和功能 - 完成用户管理页面的演示模式,包含搜索、过滤、分页等功能 - 实现通话记录页面的演示数据和录音播放功能 - 完成翻译员管理页面的演示模式 - 实现订单管理页面的完整功能 - 完成发票管理页面的演示数据 - 更新文档管理页面 - 添加 utils.ts 工具函数库 - 完善 API 路由和数据库结构 - 修复各种 TypeScript 类型错误 - 统一界面风格和用户体验
85 lines
2.0 KiB
TypeScript
85 lines
2.0 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
import { supabase } from '../../../lib/supabase'
|
|
|
|
interface UserInfo {
|
|
id: string
|
|
email: string
|
|
name: string
|
|
phone?: string
|
|
user_type: 'individual' | 'enterprise' | 'admin'
|
|
status: 'active' | 'inactive' | 'suspended'
|
|
enterprise_id?: string
|
|
avatar_url?: string
|
|
created_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
interface ApiResponse {
|
|
success: boolean
|
|
data?: UserInfo
|
|
error?: string
|
|
}
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse<ApiResponse>
|
|
) {
|
|
if (req.method !== 'GET') {
|
|
return res.status(405).json({
|
|
success: false,
|
|
error: '方法不允许'
|
|
})
|
|
}
|
|
|
|
try {
|
|
// 获取授权头
|
|
const authHeader = req.headers.authorization
|
|
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
return res.status(401).json({
|
|
success: false,
|
|
error: '未提供有效的授权令牌'
|
|
})
|
|
}
|
|
|
|
const token = authHeader.substring(7) // 移除 'Bearer ' 前缀
|
|
|
|
// 验证JWT令牌
|
|
const { data: { user }, error: authError } = await supabase.auth.getUser(token)
|
|
|
|
if (authError || !user) {
|
|
return res.status(401).json({
|
|
success: false,
|
|
error: '无效的授权令牌'
|
|
})
|
|
}
|
|
|
|
// 从数据库获取用户详细信息
|
|
const { data: userProfile, error: profileError } = await supabase
|
|
.from('users')
|
|
.select('*')
|
|
.eq('id', user.id)
|
|
.single()
|
|
|
|
if (profileError) {
|
|
console.error('Error fetching user profile:', profileError)
|
|
return res.status(404).json({
|
|
success: false,
|
|
error: '用户信息不存在'
|
|
})
|
|
}
|
|
|
|
return res.status(200).json({
|
|
success: true,
|
|
data: userProfile
|
|
})
|
|
|
|
} catch (error) {
|
|
console.error('Server error getting user info:', error)
|
|
return res.status(500).json({
|
|
success: false,
|
|
error: process.env.NODE_ENV === 'development'
|
|
? `服务器错误: ${error instanceof Error ? error.message : '未知错误'}`
|
|
: '服务器内部错误'
|
|
})
|
|
}
|
|
}
|