'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { signIn } from 'next-auth/react'; export default function RegisterPage() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const router = useRouter(); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(''); const res = await fetch('/api/register', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }), }); const data = await res.json(); if (!res.ok) { setLoading(false); setError(data.error || 'Registration failed'); return; } // Auto-login after registration const signInRes = await signIn('credentials', { redirect: false, email, password, callbackUrl: '/account/profile', }); setLoading(false); if (signInRes?.ok) { router.push('/'); } else { router.push('/account/login?registered=1'); } } return (