diff --git a/src/app/(protected)/admin/devices/page.tsx b/src/app/(protected)/admin/devices/page.tsx index 012141b..67f731f 100644 --- a/src/app/(protected)/admin/devices/page.tsx +++ b/src/app/(protected)/admin/devices/page.tsx @@ -16,13 +16,18 @@ interface DeviceDTO { export default async function DeviceManagementPage() { const user = await requireAuthOrRedirect(); - const res = await axiosServer.get('/admin/devices', { - headers: { - Authorization: `Bearer ${user.token}`, - }, - }); + try { + const res = await axiosServer.get('/admin/devices', { + headers: { + Authorization: `Bearer ${user.token}`, + }, + }); - const devices: DeviceDTO[] = res.data; + const devices: DeviceDTO[] = res.data; - return ; + return ; + } catch (error) { + console.error('Failed to fetch devices:', error); + throw new Error(`Failed to load devices: ${error instanceof Error ? error.message : 'Unknown error'}`); + } } diff --git a/src/app/(protected)/admin/users/page.tsx b/src/app/(protected)/admin/users/page.tsx index f61388d..bd98e6c 100644 --- a/src/app/(protected)/admin/users/page.tsx +++ b/src/app/(protected)/admin/users/page.tsx @@ -1,5 +1,4 @@ // src/app/admin/users/page.tsx -import { cookies } from 'next/headers'; import { requireAuthOrRedirect } from '@/lib/authServer'; import axiosServer from '@/lib/axiosServer'; import UserTableSection from '@/components/admin/UserTableSection'; @@ -19,18 +18,19 @@ interface UserDTO { export default async function UserManagementPage() { const user = await requireAuthOrRedirect(); - const cookieStore = cookies(); - // @ts-expect-error - cookies() is not actually async, type is misleading - const token = cookieStore.get('authToken')?.value; - - const res = await axiosServer.get('/admin/users', { - headers: { - Authorization: `Bearer ${user.token}`, // token is guaranteed to exist - }, - }); - - const users: UserDTO[] = res.data; - - return ; + try { + const res = await axiosServer.get('/admin/users', { + headers: { + Authorization: `Bearer ${user.token}`, + }, + }); + + const users: UserDTO[] = res.data; + + return ; + } catch (error) { + console.error('Failed to fetch users:', error); + throw new Error(`Failed to load users: ${error instanceof Error ? error.message : 'Unknown error'}`); + } }