import { useState } from 'react'; import { useRouter } from 'next/router'; export default function Register() { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const router = useRouter(); const handleSubmit = async e => { e.preventDefault(); setError(''); setLoading(true); try { const res = await fetch('/api/signup', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }) }); const data = await res.json(); if (!res.ok) throw new Error(data.message || 'Signup failed'); alert('Conta criada com sucesso! Redirecionando para login...'); router.push('/'); } catch (err) { setError(err.message); } finally { setLoading(false); } }; return (

Cadastro - Expedição Gold

{error &&

{error}

}

setUsername(e.target.value)} style={{ width: '100%', padding: '0.5rem', marginTop: '0.25rem' }} required />

setPassword(e.target.value)} style={{ width: '100%', padding: '0.5rem', marginTop: '0.25rem' }} required />

Já tem conta? Faça login

); }