import { useState } from "react"; import { useNavigate } from "react-router"; export default function Login() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const navigate = useNavigate(); const handleLogin = async (e: any) => { e.preventDefault(); try { const res = await fetch("http://localhost:3000/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username: email, password: password }) }); const data = await res.json(); if (data.success) { localStorage.setItem("token", data.token); navigate("/dashboard"); } else { alert(data.message); } } catch (error) { alert("Server error"); } }; return (

LOGIN

baru di situs ini?{" "} DAFTAR sekarang

setEmail(e.target.value)} className="w-full px-4 py-2 rounded-lg bg-gray-700 text-white placeholder-gray-400 focus:outline-none" /> setPassword(e.target.value)} className="w-full px-4 py-2 rounded-lg bg-gray-700 text-white placeholder-gray-400 focus:outline-none" />
); }