// app/login/page.tsx "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); } } return (
{step === "email" && ( <>

Log in

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

{error}

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

Check your email

We sent a login link to {email}.

The link expires in 15 minutes.

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

{step === "email" ? "Enter email" : "Check inbox"}

); }