"use client"; import { useSearchParams, useRouter } from "next/navigation"; import { useState } from "react"; export default function LoginForm() { const router = useRouter(); const searchParams = useSearchParams(); const next = searchParams.get("next") || "/machines"; const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); const [err, setErr] = useState(null); async function onSubmit(e: React.FormEvent) { e.preventDefault(); setErr(null); setLoading(true); try { const res = await fetch("/api/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password, next }), }); const data = await res.json().catch(() => ({})); if (!res.ok || !data.ok) { setErr(data.error || "Login failed"); return; } router.push(next); router.refresh(); } catch (e: any) { setErr(e?.message || "Network error"); } finally { setLoading(false); } } return (

Control Tower

Sign in to your organization

setEmail(e.target.value)} autoComplete="email" />
setPassword(e.target.value)} autoComplete="current-password" />
{err &&
{err}
}
New here?{" "} Create an account
); }