"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { Loader2 } from "lucide-react"; import { APP_NAME } from "@/lib/constants"; export default function LoginPage() { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [isLoading, setIsLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); setIsLoading(true); try { const res = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password }), }); const data = await res.json(); if (!res.ok) { setError(data.error || "Login failed"); return; } router.push("/"); router.refresh(); } catch { setError("An error occurred"); } finally { setIsLoading(false); } }; return (
Sign in to your account
Don't have an account?{" "} Create one