"use client" import { useState } from "react" import { useForm } from "react-hook-form" import { zodResolver } from "@hookform/resolvers/zod" import * as z from "zod" import { signIn } from "next-auth/react" import { useRouter } from "next/navigation" import { Loader2 } from "lucide-react" import Link from "next/link" import { Button } from "@/components/ui/button" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card" const formSchema = z.object({ email: z.string().email("Invalid email address"), password: z.string().min(1, "Password is required"), }) export default function LoginPage() { const router = useRouter() const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { email: "", password: "", }, }) async function onSubmit(values: z.infer) { setIsLoading(true) setError(null) try { const result = await signIn("credentials", { email: values.email, password: values.password, redirect: false, }) if (result?.error) { setError("Invalid email or password") return } router.push("/admin/dashboard") router.refresh() } catch (error) { setError("Something went wrong. Please try again.") } finally { setIsLoading(false) } } return (
Admin Login Enter your credentials to access the dashboard
( Email )} /> ( Password )} />
Forgot password?
{error && (
{error}
)}
) }