"use client"; import { useState } from "react"; import { API_BASE } from "@/lib/api"; export default function LoginPage() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [err, setErr] = useState(""); async function onSubmit(e){ e.preventDefault(); setErr(""); const res = await fetch(`${API_BASE}/auth/login`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password }), credentials: "include", }); if (!res.ok) { setErr("เข้าสู่ระบบไม่สำเร็จ"); return; } location.href = "/dashboard"; } return (
เข้าสู่ระบบ
setEmail(e.target.value)} /> setPassword(e.target.value)} /> {err &&
{err}
}
); }