/** * @file app/(auth)/login/page.tsx * @description Client component rendering the login page, handling form submission, authentication requests, error messaging, and redirection. */ "use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import Image from "next/image"; import { loginUser } from "@/lib/services/auth.service"; /** * Renders the user login interface and manages authentication form state. * * @returns {JSX.Element} The rendered login page component. */ export default function LoginPage() { const router = useRouter(); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); /** * Form submit handler extracting credentials from FormData and delegating to handleSignIn. * * @param {React.SubmitEvent} e - The form submission event. */ 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; await handleSignIn(email, password); }; /** * Authenticates the user with provided credentials and redirects upon success. * * @param {string} email - The user's email address. * @param {string} password - The user's password. */ const handleSignIn = async (email: string, password: string) => { setError(null); setLoading(true); const result = await loginUser(email, password); if (result.error) { setError(result.error); setLoading(false); } else { router.push("/"); } }; return (
{/* Header / Logo */}
Waveform Logo

Welcome back!

We're looking forward to seeing you again.

{/* Error Message */} {error && (
{error}
)} {/* Form */}
{/* Footer Link */}

Don't have an account yet?{" "} Register

); }