"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { authService } from "@/lib/services/auth.service"; import type { AppErrorType } from "@/types/global"; import { ErrorMessage } from "@/components/ui/ErrorMessage"; import { useTranslate } from "@/hooks/useTranslate"; interface LoginFormProps { from?: string; } export function LoginForm({ from }: LoginFormProps) { const router = useRouter(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const { t } = useTranslate(); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); setIsLoading(true); setError(null); const formData = new FormData(event.currentTarget); const email = formData.get("email") as string; const password = formData.get("password") as string; const remember = formData.get("remember") === "on"; try { await authService.login(email, password, remember); router.push(from || "/"); router.refresh(); } catch (error) { setError(error as AppErrorType); } finally { setIsLoading(false); } }; return (
{error && } ); }