"use client"; import { Loader2 } from "lucide-react"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { api } from "@/lib/api"; export default function BootstrapPage() { const router = useRouter(); const [loading, setLoading] = useState(false); const [checkingStatus, setCheckingStatus] = useState(true); const [error, setError] = useState(""); useEffect(() => { const checkStatus = async () => { try { const { data } = await api.bootstrap.status.get(); if (data && !data.needsSetup) { router.replace("/login"); } } catch (err) { console.error("Failed to check bootstrap status:", err); } finally { setCheckingStatus(false); } }; checkStatus(); }, [router]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(""); const formData = new FormData(e.currentTarget); const email = formData.get("email") as string; const password = formData.get("password") as string; const confirmPassword = formData.get("confirmPassword") as string; const name = formData.get("name") as string; if (password !== confirmPassword) { setError("Passwords do not match"); setLoading(false); return; } try { const { data, error: apiError } = await api.bootstrap.setup.post({ email, password, name, }); if (apiError) { const errorMessage = "value" in apiError && typeof apiError.value === "object" && apiError.value && "message" in apiError.value ? String(apiError.value.message) : "Failed to create admin user"; setError(errorMessage); } else if (data?.success) { router.push("/login"); } else { setError("Failed to create admin user"); } } catch (err) { setError("Failed to connect to server"); } finally { setLoading(false); } }; if (checkingStatus) { return (
); } return (
Welcome to Minikura Create your admin account to get started
{error && (
{error}
)}
); }