'use client'; import { zodResolver } from '@hookform/resolvers/zod'; import { Loader2 } from 'lucide-react'; import { useRouter, useSearchParams } from 'next/navigation'; import { useTranslations } from 'next-intl'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { OAuthButtons } from '@/components/auth/oauth-buttons'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Link } from '@/i18n/navigation'; import { useAuthStore } from '@/lib/auth-store'; import { loginSchema, type LoginFormData } from '@/lib/validations/auth'; export default function LoginPage() { const router = useRouter(); const searchParams = useSearchParams(); const { login, isLoading, error, clearError } = useAuthStore(); const [showPassword, setShowPassword] = useState(false); const t = useTranslations('auth'); const oauthError = searchParams.get('error'); const oauthErrorMessage = oauthError ? t(`oauthErrors.${oauthError}` as Parameters[0]) ?? t('oauthErrors.default') : null; const { register, handleSubmit, formState: { errors }, } = useForm({ resolver: zodResolver(loginSchema), }); const onSubmit = async (data: LoginFormData) => { try { await login(data); router.push('/'); } catch { // Error is handled by the store } }; return ( {t('loginTitle')} {t('loginDescription')}
{oauthErrorMessage && (
{oauthErrorMessage}
)} {error && (
{error}
)}
{errors.phone && ( )}
{errors.password && ( )}
{t('orLoginWith')}

{t('noAccount')}{' '} {t('registerLink')}

); }