"use client"; import { useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { useTranslations } from "next-intl"; import { authClient } from "@/lib/auth/client"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Separator } from "@/components/ui/separator"; export default function LoginPage() { const router = useRouter(); const t = useTranslations("auth"); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); const [unverified, setUnverified] = useState(false); const [resending, setResending] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setUnverified(false); setLoading(true); const { error } = await authClient.signIn.email({ email, password, callbackURL: "/recipes" }); setLoading(false); if (error) { if (error.code === "EMAIL_NOT_VERIFIED") { setUnverified(true); } else { toast.error(error.message ?? "Sign in failed"); } } else { router.push("/recipes"); } } async function resendVerification() { setResending(true); const { error } = await authClient.sendVerificationEmail({ email, callbackURL: "/recipes", }); setResending(false); if (error) { toast.error(error.message ?? "Failed to resend"); } else { toast.success("Verification email sent — check your inbox"); setUnverified(false); } } async function handleGoogle() { await authClient.signIn.social({ provider: "google", callbackURL: "/recipes" }); } return ( Epicure {t("signInTitle")}
{t("or")}
{ setEmail(e.target.value); setUnverified(false); }} required />
{t("forgotPassword")}
setPassword(e.target.value)} required />
{unverified && (

{t("emailNotVerified")}

{t("checkInboxVerification")}

)}

{t("noAccount")}{" "} {t("signUp")}

); }