"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { signUpWithUsername } from "@/lib/auth-client"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { toast } from "sonner"; import { Loader2 } from "lucide-react"; export default function RegisterPage() { const router = useRouter(); const [loading, setLoading] = useState(false); const [formData, setFormData] = useState({ name: "", username: "", email: "", password: "", }); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); if (formData.username.length < 3) { toast.error("Username must be at least 3 characters"); setLoading(false); return; } if (!/^[a-zA-Z0-9_-]+$/.test(formData.username)) { toast.error("Username can only contain letters, numbers, hyphens, and underscores"); setLoading(false); return; } try { const { error } = await signUpWithUsername({ email: formData.email, password: formData.password, name: formData.name, username: formData.username.toLowerCase(), }); if (error) { toast.error(error.message || "Failed to create account"); return; } toast.success("Account created successfully!"); router.push("/"); router.refresh(); } catch { toast.error("Something went wrong"); } finally { setLoading(false); } } return (
Already have an account?{" "} Sign in