"use client"; import { cn } from "@/lib/utils"; import { createClient } from "@/lib/supabase/client"; 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 Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; export function SignUpForm({ className, ...props }: React.ComponentPropsWithoutRef<"div">) { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [repeatPassword, setRepeatPassword] = useState(""); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const router = useRouter(); const handleSignUp = async (e: React.FormEvent) => { e.preventDefault(); const supabase = createClient(); setIsLoading(true); setError(null); if (password !== repeatPassword) { setError("Passwords do not match"); setIsLoading(false); return; } try { const { error } = await supabase.auth.signUp({ email, password, options: { emailRedirectTo: `${window.location.origin}/protected`, }, }); if (error) throw error; router.push("/auth/sign-up-success"); } catch (error: unknown) { setError(error instanceof Error ? error.message : "An error occurred"); } finally { setIsLoading(false); } }; return (
Sign up Create a new account
setEmail(e.target.value)} />
setPassword(e.target.value)} />
setRepeatPassword(e.target.value)} />
{error &&

{error}

}
Already have an account?{" "} Login
); }