Something went wrong. Try again.
Testing building apps with atproto
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import { Show } from "../lib/components"import { html, atom, derived } from "../lib/core"const ErrorMessage = (key) => html`<p ${key}>Error</p>`
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` <form ${{ onsubmit: handleSubmit }}> <label for="handle_input">Atproto handle</label> <input ${{ oninput: (e) => { handle.set(e.target.value) }, value: handle, disabled: loading }} type="text" id="handle_input" placeholder="user.example.com" >
${Show(ErrorMessage, { when: error })} <button ${{ disabled: loading }}> ${submitDisplayText} </button> </form> `}