feat(users): fetch user by id from backend
This commit is contained in:
@@ -15,7 +15,7 @@ import { notFound } from "next/navigation"
|
|||||||
|
|
||||||
export default async function UserProfilePage({ params }: { params: Promise<{ id: string }> }) {
|
export default async function UserProfilePage({ params }: { params: Promise<{ id: string }> }) {
|
||||||
const { id } = await params
|
const { id } = await params
|
||||||
const user = getUserById(id)
|
const user = await getUserById(id)
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
notFound()
|
notFound()
|
||||||
|
|||||||
+8
-2
@@ -1,4 +1,5 @@
|
|||||||
import { httpJson } from "@/lib/api/http"
|
import { httpJson } from "@/lib/api/http"
|
||||||
|
import { isApiError } from "@/lib/errors"
|
||||||
import { mockUsers } from "@/lib/mock"
|
import { mockUsers } from "@/lib/mock"
|
||||||
import type { User } from "@/lib/types"
|
import type { User } from "@/lib/types"
|
||||||
|
|
||||||
@@ -6,8 +7,13 @@ export function listUsers() {
|
|||||||
return mockUsers
|
return mockUsers
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUserById(userId: string) {
|
export async function getUserById(userId: string): Promise<User | undefined> {
|
||||||
return mockUsers.find((user) => user.id === userId)
|
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> {
|
export async function getCurrentUserForLogin(): Promise<User> {
|
||||||
|
|||||||
Reference in New Issue
Block a user