/* ============================================================ auth.jsx — Tela de login / cadastro (modo Supabase) ============================================================ */ function AuthScreen({ onAuthed }) { const [mode, setMode] = React.useState('signin'); // 'signin' | 'signup' const [email, setEmail] = React.useState(''); const [senha, setSenha] = React.useState(''); const [busy, setBusy] = React.useState(false); const [err, setErr] = React.useState(''); const [msg, setMsg] = React.useState(''); const submit = async (e) => { e.preventDefault(); setErr(''); setMsg(''); setBusy(true); try { if (mode === 'signin') { await window.crmStore.signIn(email.trim(), senha); onAuthed(); } else { const res = await window.crmStore.signUp(email.trim(), senha); if (res && res.session) { onAuthed(); } else { setMsg('Conta criada! Verifique seu e-mail para confirmar e depois entre.'); setMode('signin'); } } } catch (e2) { const m = (e2 && e2.message) || 'Não foi possível concluir.'; setErr(/invalid login/i.test(m) ? 'E-mail ou senha incorretos.' : m); } finally { setBusy(false); } }; return (
{mode === 'signin' ? 'Acesse o painel comercial da ' + window.brandName() + '.' : 'Crie seu acesso para gerenciar o pipeline.'}