feat(users): fetch user by id from backend

This commit is contained in:
zetaloop
2026-02-28 16:42:33 +08:00
parent f1ae3e04bb
commit 536465aa54
2 changed files with 9 additions and 3 deletions
+8 -2
View File
@@ -1,4 +1,5 @@
import { httpJson } from "@/lib/api/http"
import { isApiError } from "@/lib/errors"
import { mockUsers } from "@/lib/mock"
import type { User } from "@/lib/types"
@@ -6,8 +7,13 @@ export function listUsers() {
return mockUsers
}
export function getUserById(userId: string) {
return mockUsers.find((user) => user.id === userId)
export async function getUserById(userId: string): Promise<User | undefined> {
try {
return await httpJson<User>(`/api/v1/users/${userId}`)
} catch (err) {
if (isApiError(err) && err.code === 404) return undefined
throw err
}
}
export async function getCurrentUserForLogin(): Promise<User> {