'use client'; import { useActionState, useRef, useState, Suspense } from 'react'; import { useFormStatus } from 'react-dom'; import { authenticate } from '@/app/actions/auth'; import Link from 'next/link'; import { useSearchParams } from 'next/navigation'; import { Mail, Lock, ArrowRight, Sparkles } from 'lucide-react'; import { useLanguage } from '@/lib/i18n'; import { GoogleSignInButton } from '@/components/google-sign-in-button'; import { resendSignupVerification } from '@/app/actions/auth-verify'; import { toast } from 'sonner'; function AuthDivider({ label }: { label: string }) { return (
{label}
); } function LoginButton() { const { pending } = useFormStatus(); const { t } = useLanguage(); return ( ); } function LoginFormInner({ allowRegister = true, googleAuthEnabled = false, authError, }: { allowRegister?: boolean; googleAuthEnabled?: boolean; authError?: string; }) { const [errorMessage, dispatch] = useActionState(authenticate, undefined); const { t, language } = useLanguage(); const searchParams = useSearchParams(); const emailRef = useRef(null); const [resending, setResending] = useState(false); const verified = searchParams.get('verified') === '1'; const oauthError = authError === 'SessionRequired' ? t('auth.sessionExpired') : authError === 'OAuthAccountNotLinked' ? t('auth.oauthAccountNotLinked') : authError ?? null; const showUnverified = errorMessage === 'EMAIL_NOT_VERIFIED'; const handleResend = async () => { const email = emailRef.current?.value?.trim() ?? ''; if (!email) { toast.error(t('auth.verifyMissingEmail')); return; } setResending(true); const result = await resendSignupVerification(email, language); setResending(false); if (result.success) toast.success(t('auth.verifyResent')); else toast.error(t('auth.verifyResendFailed')); }; return (

{t('auth.welcomeBack')}

{t('auth.welcomeBackSubtitle')}

{verified && (

{t('auth.emailVerifiedBanner')}

)} {oauthError && (

{oauthError}

)} {googleAuthEnabled && ( <> )}
{t('auth.forgot')}
{showUnverified && (

{t('auth.emailNotVerified')}

)} {errorMessage && !showUnverified && (

{errorMessage === 'Invalid credentials.' ? t('auth.invalidCredentials') : errorMessage}

)}
{allowRegister && (

{t('auth.noAccount')}{' '} {t('auth.signUp')}

)}
); } export function LoginForm(props: { allowRegister?: boolean; googleAuthEnabled?: boolean; authError?: string; }) { return (
}> ); }