"use client" import { FormEvent, useEffect, useState } from "react" import AuthShell from "../components/AuthShell" export default function LoginPage() { const [nextPath, setNextPath] = useState("/") const [password, setPassword] = useState("") const [message, setMessage] = useState("") const [busy, setBusy] = useState(false) useEffect(() => { setNextPath(new URLSearchParams(window.location.search).get("next") || "/") }, []) const submit = async (event: FormEvent) => { event.preventDefault() setBusy(true) setMessage("") try { const response = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ password, next: nextPath }), }) const data = await response.json() if (!response.ok) throw new Error(data.error || "Login failed") window.location.href = data.next || "/" } catch (error) { setMessage(error instanceof Error ? error.message : "Login failed") } finally { setBusy(false) } } return (
{message && (
{message}
)}
Setup Account Forgot Password?
) }