"use client"; import { useState } from "react"; export function LoginForm() { const [handle, setHandle] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); async function handleSubmit(e: React.SubmitEvent) { e.preventDefault(); setLoading(true); setError(null); try { const res = await fetch("/oauth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ handle }), }); const data = await res.json(); if (!res.ok) { throw new Error(data.error || "Login failed"); } // Redirect to authorization server window.location.href = data.redirectUrl; } catch (err) { setError(err instanceof Error ? err.message : "Login failed"); setLoading(false); } } return (
setHandle(e.target.value)} placeholder="user.example.com" className="w-full px-3 py-2 border border-zinc-300 dark:border-zinc-700 rounded-lg bg-white dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100" disabled={loading} />
{error &&

{error}

}
); }