"use client"; import { fetchData } from "@/lib/data-service"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Image from "next/image"; import Link from "next/link"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; export default function RegisterPage() { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [invitationCode, setInvitationCode] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const router = useRouter(); async function handleRegister(e: React.FormEvent) { e.preventDefault(); setError(""); setLoading(true); const res = await fetchData( `/api/auth/register`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password, invitationCode }), } ); const data = await res; if (res) { console.log("Registered successfully:", data); router.push("/auth/login"); } else { setError(data.error || "Registration failed"); } setLoading(false); } return (
Sign up to start selling
{error}
}Already have an account?{" "} Sign in