// app/vault/page.tsx "use client"; import Link from "next/link"; import { useEffect, useMemo, useState } from "react"; import { useRouter } from "next/navigation"; import { useAuth } from "@/context/AuthContext"; type BuildDto = { id: string; uuid: string; // UUID string title: string; description?: string | null; isPublic?: boolean | null; createdAt?: string | null; updatedAt?: string | null; }; const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080"; function fmt(d?: string | null) { if (!d) return "—"; const dt = new Date(d); if (Number.isNaN(dt.getTime())) return d; return dt.toLocaleString(); } export default function VaultPage() { const router = useRouter(); const { user, loading, getAuthHeaders } = useAuth(); const [builds, setBuilds] = useState([]); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const authed = !!user; useEffect(() => { if (!loading && !authed) { router.replace("/login"); } }, [loading, authed, router]); const headers = useMemo(() => getAuthHeaders(), [getAuthHeaders]); useEffect(() => { if (loading || !authed) return; let cancelled = false; (async () => { setBusy(true); setError(null); try { const res = await fetch(`${API_BASE_URL}/api/v1/products/me/builds`, { method: "GET", headers, }); if (!res.ok) { const text = await res.text().catch(() => ""); throw new Error(text || `Request failed (${res.status})`); } const data = (await res.json()) as BuildDto[]; if (!cancelled) setBuilds(Array.isArray(data) ? data : []); } catch (e: any) { if (!cancelled) setError(e?.message || "Failed to load builds"); } finally { if (!cancelled) setBusy(false); } })(); return () => { cancelled = true; }; }, [loading, authed, headers]); if (loading) { return (
Loading…
); } // If not authed, we already redirected; render nothing. if (!authed) return null; return (

Vault

Your saved builds. Load one into the builder or publish it later.

New Build Account →
{error ? (
{error}
) : null}
My Builds
{busy ? "Refreshing…" : `${builds.length} total`}
{builds.length === 0 ? (
No builds yet. Create one in the builder and hit “Save to Vault”.
) : (
    {builds.map((b) => (
  • {b.title}
    Updated: {fmt(b.updatedAt)} • UUID:{" "} {b.uuid}
    {b.description ? (
    {b.description}
    ) : null}
    {/* Placeholder: wire this to "load into builder" next */} Open
  • ))}
)}
); }