/* global React, Icon, LogoMark, api */ const { useState: useStateAuth } = React; function AuthModal({ open, mode="signup", onClose, onSwitch, onSuccess }){ if (!open) return null; const [email, setEmail] = useStateAuth(""); const [password, setPassword] = useStateAuth(""); const [handle, setHandle] = useStateAuth(""); const [busy, setBusy] = useStateAuth(false); const [errorMsg, setErrorMsg] = useStateAuth(""); const [info, setInfo] = useStateAuth(""); const isSignup = mode === "signup"; const submit = async () => { setErrorMsg(""); setInfo(""); if (!email || !password) { setErrorMsg("Email and password required."); return; } if (isSignup && password.length < 8) { setErrorMsg("Password must be at least 8 characters."); return; } setBusy(true); if (isSignup) { const r = await api.signUp({ email, password, displayName: handle ? handle.replace(/^@/,"") : email.split("@")[0] }); if (r.error) { setErrorMsg(r.error.message || "Sign-up failed"); setBusy(false); return; } // Save handle if provided if (handle) { setTimeout(async () => { await api.updateMyProfile({ handle: handle.startsWith("@") ? handle : "@"+handle }); }, 600); } // If email confirmation is required, Supabase returns user with no session if (!r.data || !r.data.session) { setInfo("Account created! Check your email to confirm, then log in."); setBusy(false); return; } setBusy(false); onSuccess && onSuccess(); } else { const r = await api.signIn({ email, password }); setBusy(false); if (r.error) { setErrorMsg(r.error.message || "Login failed"); return; } onSuccess && onSuccess(); } }; const onKey = (e) => { if (e.key === "Enter") submit(); }; return (
{isSignup ? "Takes 60 seconds. You'll be in the dashboard right after." : "Log in to your Clippr dashboard."}