"use client"; import { useState } from "react"; type Step = "email" | "sent"; export default function LoginPage() { const [email, setEmail] = useState(""); const [step, setStep] = useState("email"); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); async function submit() { setLoading(true); setError(null); try { const res = await fetch("/api/auth/request-link", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email }), }); if (!res.ok) { throw new Error("Failed to send login link"); } setStep("sent"); } catch (e) { setError("Something went wrong. Try again."); } finally { setLoading(false); } } const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === "Enter" && !loading && email && step === "email") { submit(); } }; return (
{/* Navigation */} {/* Main Content */}
{/* Progress Bar */} {/* Form Card */}
{step === "email" && ( <>

Welcome back

Sign in to your Stripe to Xero automation dashboard

setEmail(e.target.value)} onKeyPress={handleKeyPress} disabled={loading} autoFocus />
{error && (

{error}

)}
)} {step === "sent" && ( <>

Check your email

We've sent a login link to {email}

The link expires in 15 minutes. Check your spam folder if you don't see it.

)}
{/* Footer */}

Magic link authentication is secure and passwordless

); } function Progress({ step }: { step: Step }) { const percent = step === "email" ? 50 : 100; return (

{step === "email" ? "Step 1 of 2 • Enter email" : "Step 2 of 2 • Check inbox"}

); }