更新用户信息API路由,调整为'/me/profile',并在设置页面中整合用户信息获取逻辑,优化加载状态处理,提升用户体验和代码可维护性。

This commit is contained in:
zyh
2025-04-10 14:16:54 +00:00
parent 21ee486676
commit 8d74bdbe79
3 changed files with 39 additions and 11 deletions

View File

@@ -238,14 +238,14 @@ export function createUserRoutes(withAuth: WithAuth) {
})
// 获取当前用户信息
usersRoutes.get('/me', withAuth, async (c) => {
usersRoutes.get('/me/profile', withAuth, async (c) => {
try {
const user = c.get('user')!
const apiClient = c.get('apiClient')
const userData = await apiClient.database.table('users')
.where('id', user.id)
.select('id', 'username', 'nickname', 'email', 'phone', 'role', 'created_at')
.select('id', 'username', 'nickname', 'email', 'phone', 'created_at')
.first()
if (!user) {
@@ -253,7 +253,7 @@ export function createUserRoutes(withAuth: WithAuth) {
}
return c.json({
data: user,
data: userData,
message: '获取用户详情成功'
})
} catch (error) {
@@ -263,7 +263,7 @@ export function createUserRoutes(withAuth: WithAuth) {
})
// 更新当前用户信息
usersRoutes.put('/me', withAuth, async (c) => {
usersRoutes.put('/me/profile', withAuth, async (c) => {
try {
const user = c.get('user')!
const apiClient = c.get('apiClient')
@@ -294,7 +294,7 @@ export function createUserRoutes(withAuth: WithAuth) {
const updatedUser = await apiClient.database.table('users')
.where('id', user.id)
.select('id', 'username', 'nickname', 'email', 'phone', 'role', 'created_at')
.select('id', 'username', 'nickname', 'email', 'phone', 'created_at')
.first()
return c.json({