'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Alert, AlertDescription } from '@/components/ui/alert'; import Loader2 from 'lucide-react/dist/esm/icons/loader-2'; import Eye from 'lucide-react/dist/esm/icons/eye'; import EyeOff from 'lucide-react/dist/esm/icons/eye-off'; import CheckCircle from 'lucide-react/dist/esm/icons/check-circle'; import { signUpWithRole } from '@/lib/supabase'; export function SignUpForm() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const [success, setSuccess] = useState(false); const router = useRouter(); const validateForm = () => { if (password !== confirmPassword) { setError('Passwords do not match'); return false; } if (password.length < 6) { setError('Password must be at least 6 characters long'); return false; } return true; }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setSuccess(false); if (!validateForm()) return; setIsLoading(true); try { const { data, error } = await signUpWithRole(email, password); if (error) { if (error.message.includes('User already registered')) { setError('An account with this email already exists. Please sign in instead.'); } else if (error.message.includes('Password should be at least')) { setError('Password must be at least 6 characters long.'); } else { setError(error.message); } return; } if (data.user) { setSuccess(true); setTimeout(() => { router.push('/sign-in'); }, 2000); } } catch { setError('An unexpected error occurred. Please try again.'); } finally { setIsLoading(false); } }; if (success) { return (

Account created successfully!

Please check your email and click the confirmation link to activate your account.

); } return ( Create account Sign up to get started with your new account

New accounts are created as user. Set app_metadata.role = "admin" in the Supabase Dashboard to grant admin access.

{error && ( {error} )}
setEmail(e.target.value)} required disabled={isLoading} className="border-futuristic" />
setPassword(e.target.value)} required disabled={isLoading} className="border-futuristic pr-10" />
setConfirmPassword(e.target.value)} required disabled={isLoading} className="border-futuristic pr-10" />
Already have an account?
); }