// auth.jsx — sign-in / sign-up and the e-mail verification round trip. // Loaded from index.html as an ordered `text/babel` classic script (position 4 of 8). // Classic scripts share one global scope — see docs/engineering/Patterns.md §9. // ─── Auth Pages ────────────────────────────────────────────────────────────── function AuthPage({ mode }) { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [fullName, setFullName] = useState(""); const [company, setCompany] = useState(""); const [addressLine1, setAddressLine1] = useState(""); const [city, setCity] = useState(""); const [postalCode, setPostalCode] = useState(""); const [country, setCountry] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const isRegister = mode === "register"; const params = new URLSearchParams(window.location.hash.split("?")[1] || ""); const selectedPlan = params.get("plan") || "business"; const handleSubmit = async () => { if (isRegister) return; // Sign-ups are disabled in the UI. setError(""); setLoading(true); try { const endpoint = isRegister ? "/auth/register" : "/auth/login"; const body = isRegister ? { email, password, full_name: fullName, company_name: company, address_line1: addressLine1, city, postal_code: postalCode, country, plan: selectedPlan } : { email, password }; const data = await apiCall(endpoint, { method: "POST", body: JSON.stringify(body), }); if (isRegister && (data.status === "verification_required" || data.status === "verification_unavailable")) { const delivery = data.status === "verification_unavailable" ? "&delivery=unavailable" : ""; window.location.hash = `#/check-email?email=${encodeURIComponent(data.email || email)}${delivery}`; return; } if (!data.token) throw new Error("Authentication response did not include a token"); localStorage.setItem("zs_token", data.token); window.location.hash = "#/dashboard"; } catch (e) { setError(e.message); } finally { setLoading(false); } }; return (
{/* Left panel */}

{isRegister ? "Get started in minutes" : "Welcome back"}

{isRegister ? "Create your account, choose a plan, and your MDM server will be provisioned automatically. Takes less than 60 seconds." : "Sign in to manage your instances and monitor your device fleet."}

✓
Instant provisioning
Server live within 60 seconds
✓
14-day free trial
No credit card required
{/* Right panel — form */}

{isRegister ? "Create your account" : "Sign in"}

{error && (
{error}
)} {isRegister && ( setFullName(e.target.value)} /> )} {isRegister && ( setCompany(e.target.value)} /> )} setEmail(e.target.value)} /> setPassword(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleSubmit()} /> {isRegister && ( <> setAddressLine1(e.target.value)} />
setCity(e.target.value)} />
setPostalCode(e.target.value)} />
)} {isRegister && (
Selected plan:{" "} {PLANS.find((p) => p.id === selectedPlan)?.name || "Business"} {" "} — 14-day free trial included
)} {isRegister && (

Signups are disabled currently

)}

{isRegister ? ( <> Already have an account?{" "} Sign in ) : ( <> Don't have an account?{" "} Signups are disabled currently
Resend verification email )}

); } function CheckEmailPage() { const params = new URLSearchParams(window.location.hash.split("?")[1] || ""); const email = params.get("email") || ""; const [deliveryUnavailable, setDeliveryUnavailable] = useState(params.get("delivery") === "unavailable"); const [message, setMessage] = useState({ text: "", error: false }); const [loading, setLoading] = useState(false); const resend = async () => { if (!email) return; setLoading(true); setMessage({ text: "", error: false }); try { const data = await apiCall("/auth/resend-verification", { method: "POST", body: JSON.stringify({ email }), }); setDeliveryUnavailable(false); setMessage({ text: data.message, error: false }); } catch (e) { setMessage({ text: e.message, error: true }); } finally { setLoading(false); } }; return (

{deliveryUnavailable ? "Verification temporarily unavailable" : "Check your email"}

{deliveryUnavailable ? ( "Your account was created, but verification email delivery is temporarily unavailable. Try again later or contact support." ) : ( <>We sent a verification link to {email || "your email address"}. Your MDM server will be provisioned after you verify your address. )}

{message.text &&

{message.text}

} Back to sign in
); } function VerifyEmailPage() { const params = new URLSearchParams(window.location.hash.split("?")[1] || ""); const token = params.get("token") || ""; const [state, setState] = useState({ status: "verifying", error: "", warning: "" }); useEffect(() => { if (!token) { setState({ status: "error", error: "The verification link is missing its token.", warning: "" }); return; } let active = true; apiCall(`/auth/verify-email?token=${encodeURIComponent(token)}`) .then((data) => { if (!active) return; if (!data.token) throw new Error("Verification response did not include a token"); localStorage.setItem("zs_token", data.token); setState({ status: "verified", error: "", warning: data.provisioning_error || "" }); }) .catch((error) => { if (active) setState({ status: "error", error: error.message, warning: "" }); }); return () => { active = false; }; }, [token]); const verified = state.status === "verified"; return (

{state.status === "verifying" ? "Verifying your email…" : verified ? "Email verified" : "Verification failed"}

{state.status === "verifying" ? "Please wait while we activate your account." : verified ? state.warning || "Your account is active and your MDM server is being provisioned." : state.error}

{verified ? ( ) : state.status === "error" ? ( Back to sign in ) : null}
); }