'use client'; import { useState } from 'react'; export default function SignUp() { const [formData, setFormData] = useState({ name: '', email: '', password: '', confirmPassword: '' }); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [success, setSuccess] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); if (formData.password !== formData.confirmPassword) { setError('Passwords do not match'); setLoading(false); return; } try { const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/auth/register`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: formData.name, email: formData.email, password: formData.password }) }); const data = await response.json(); if (!response.ok) { setError(data.error || 'Registration failed'); } else { setSuccess(true); setTimeout(() => { window.location.href = '/auth/signin'; }, 2000); } } catch (err) { setError('Registration failed'); } finally { setLoading(false); } }; if (success) { return (
Redirecting to sign in...