"use client" import { useState } from "react" import { signIn } from "next-auth/react" import { useRouter } from "next/navigation" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { Eye, EyeOff, Loader2 } from "lucide-react" import Link from "next/link" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Alert, AlertDescription } from "@/components/ui/alert" import { loginSchema, type LoginInput } from "@/lib/validation" export default function SignInPage() { const [showPassword, setShowPassword] = useState(false) const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState("") const router = useRouter() const form = useForm({ resolver: zodResolver(loginSchema), defaultValues: { email: "", password: "", }, }) const onSubmit = async (data: LoginInput) => { setIsLoading(true) setError("") try { const result = await signIn("credentials", { email: data.email, password: data.password, redirect: false, }) if (result?.error) { setError("Invalid email or password") } else { router.push("/") router.refresh() } } catch { setError("An unexpected error occurred") } finally { setIsLoading(false) } } return (
Sign In Enter your email and password to access your account {error && ( {error} )}
( Email )} /> ( Password
)} />
Don't have an account? Sign up
) }