import { Show } from "../lib/components" import { html, atom, derived } from "../lib/core" const ErrorMessage = (key) => html`
Error
` export const LoginForm = () => { const handle = atom("") const loading = atom(false) const error = atom(null) /** @param {SubmitEvent} e */ const handleSubmit = async (e) => { e.preventDefault() loading.set(true) error.set(null) try { const res = await fetch("/api/oauth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ handle: handle.value }), }); 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) { error.set(err instanceof Error ? err.message : "Login failed"); loading.set(false); } } const submitDisplayText = derived(() => { return loading.value ? "Signing in ..." : "Sign in" }, [loading]); return html` ` }