makearmy-app/app/my/rigs/page.tsx
2025-09-26 18:30:40 -04:00

43 lines
1.3 KiB
TypeScript

// app/my/rigs/page.tsx
import { cookies } from "next/headers";
import SignOutButton from "@/components/SignOutButton";
import RigBuilderClient from "./RigBuilderClient";
const API_BASE = process.env.DIRECTUS_URL!;
type RigType = { id: number | string; name: string };
async function loadRigTypes(): Promise<RigType[]> {
const ck = await cookies();
const at = ck.get("ma_at")?.value;
const headers: Record<string, string> = { Accept: "application/json" };
if (at) headers.Authorization = `Bearer ${at}`;
const res = await fetch(
`${API_BASE}/items/user_rig_type?fields=id,name&sort=sort`,
{ cache: "no-store", headers }
);
if (!res.ok) {
console.warn("[my/rigs] failed to load rig types:", await res.text());
return [];
}
const json = await res.json();
return (json?.data ?? []) as RigType[];
}
export default async function MyRigsPage() {
const rigTypes = await loadRigTypes();
return (
<div className="mx-auto max-w-5xl px-4 py-8 space-y-8">
<header className="flex items-center justify-between">
<h1 className="text-2xl font-semibold">My Rigs</h1>
<SignOutButton redirectTo="/auth/sign-in" />
</header>
<RigBuilderClient rigTypes={rigTypes} />
</div>
);
}