From e0f2b22bb3d02eff64d40a3ba0510cb4773dce44 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Mon, 12 Oct 2026 10:41:09 +0200 Subject: [PATCH] feat(auth): enable submit buttons only when form fields are complete --- app/(auth)/login/page.tsx | 41 ++++++++++++++++++------------ app/(auth)/register/page.tsx | 48 ++++++++++++++++++++++++++++-------- 2 files changed, 63 insertions(+), 26 deletions(-) diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx index 588c871..02871e3 100644 --- a/app/(auth)/login/page.tsx +++ b/app/(auth)/login/page.tsx @@ -1,6 +1,6 @@ /** * @file app/(auth)/login/page.tsx - * @description Client component rendering the login page, handling form submission, authentication requests, error messaging, autocomplete, and redirection. + * @description Client component rendering the login page, handling form submission, authentication requests, error messaging, autocomplete, form validation, and redirection. */ "use client"; @@ -11,7 +11,7 @@ import Link from "next/link"; import Image from "next/image"; import { loginAsGuest, loginUser } from "@/lib/services/auth.service"; -/** Renders the user login interface and manages authentication form state. */ +/** Renders the user login interface, manages authentication form state, and enforces input completion for form submission. */ export default function LoginPage() { const router = useRouter(); const [error, setError] = useState(null); @@ -19,6 +19,11 @@ export default function LoginPage() { "credentials" | "guest" | null >(null); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + + const isFormValid = email.trim() !== "" && password.trim() !== ""; + /** Clears active error state when user modifies input fields. */ const handleInputChange = () => { if (error) { @@ -27,24 +32,22 @@ export default function LoginPage() { }; /** Form submit handler extracting credentials from FormData and delegating to handleSignIn. */ - const handleSubmit = async (e: React.FormEvent) => { + const handleSubmit = async (e: React.SubmitEvent) => { e.preventDefault(); - const formData = new FormData(e.currentTarget); - const email = formData.get("email") as string; - const password = formData.get("password") as string; + if (!isFormValid) return; await handleSignIn(email, password, "credentials"); }; /** Authenticates the user with provided credentials and redirects upon success. */ const handleSignIn = async ( - email: string, - password: string, + loginEmail: string, + loginPass: string, type: "credentials" | "guest", ) => { setError(null); setLoadingType(type); - const result = await loginUser(email, password); + const result = await loginUser(loginEmail, loginPass); if (result.error) { setError(result.error); @@ -98,11 +101,7 @@ export default function LoginPage() { )} {/* Form */} -
+