"use client"; import { signIn } from "next-auth/react"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; export default function LoginPage() { const router = useRouter(); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(""); const formData = new FormData(e.currentTarget); const res = await signIn("credentials", { username: formData.get("username"), password: formData.get("password"), redirect: false, }); if (res?.error) { setError("Invalid credentials"); setLoading(false); } else { router.push("/admin"); } } return (
Admin Login
{error && (

{error}

)}
Back to dashboard
); }