// 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 (
{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."}
Signups are disabled currently
)}
{isRegister ? (
<>
Already have an account?{" "}
Sign in
>
) : (
<>
Don't have an account?{" "}
Signups are disabled currently
Resend verification 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{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}