diff --git a/app/register/page.tsx b/app/register/page.tsx new file mode 100644 index 0000000..7a5714d --- /dev/null +++ b/app/register/page.tsx @@ -0,0 +1,109 @@ +"use client"; + +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 fetch("https://internal-api.inboxi.ng/api/auth/register", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ username, password, invitationCode }), + }); + + const data = await res.json(); + + if (res.ok) { + console.log("Registered successfully:", data); + + router.push("/login"); + } else { + setError(data.error || "Registration failed"); + } + + setLoading(false); + } + + return ( +
+
+
+

Create an Account

+

Sign up to start selling

+
+ + {error &&

{error}

} + +
+
+
+ + setUsername(e.target.value)} + className="mt-1" + /> +
+
+ + setPassword(e.target.value)} + className="mt-1" + /> +
+
+ + setInvitationCode(e.target.value)} + className="mt-1" + /> +
+
+ + +
+ +

+ Already have an account?{" "} + + Sign in + +

+
+
+ ); +} \ No newline at end of file