/** * @file app/(auth)/login/page.tsx * @description Client component rendering the login page, handling form submission, authentication requests, error messaging, autocomplete, form validation, and redirection. */ "use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import Image from "next/image"; import { loginAsGuest, loginUser } from "@/lib/services/auth.service"; /** 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); const [loadingType, setLoadingType] = useState< "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) { setError(null); } }; /** Form submit handler extracting credentials from FormData and delegating to handleSignIn. */ const handleSubmit = async (e: React.SubmitEvent) => { e.preventDefault(); if (!isFormValid) return; await handleSignIn(email, password, "credentials"); }; /** Authenticates the user with provided credentials and redirects upon success. */ const handleSignIn = async ( loginEmail: string, loginPass: string, type: "credentials" | "guest", ) => { setError(null); setLoadingType(type); const result = await loginUser(loginEmail, loginPass); if (result.error) { setError(result.error); setLoadingType(null); } else { router.push("/"); } }; /** Triggers secure guest authentication via the backend service. */ const handleGuestLogin = async () => { setError(null); setLoadingType("guest"); const result = await loginAsGuest(); if (result.error) { setError(result.error); setLoadingType(null); return; } router.push("/"); }; return (
{/* Header / Logo */}
Waveform Logo

Welcome back!

We're looking forward to seeing you again.

{/* Error Message */} {error && (
{error}
)} {/* Form */}
{ setEmail(e.target.value); handleInputChange(); }} placeholder="name@example.com" maxLength={255} autoComplete="email" className="w-full bg-neutral-900 border border-neutral-800 rounded-lg px-3 py-2 text-foreground placeholder-neutral-500 outline-none focus:border-accent transition-colors text-sm" />
{ setPassword(e.target.value); handleInputChange(); }} placeholder="•••••••••••••" maxLength={72} autoComplete="current-password" className="w-full bg-neutral-900 border border-neutral-800 rounded-lg px-3 py-2 text-foreground placeholder-neutral-500 outline-none focus:border-accent transition-colors text-sm" />
or
{/* Footer Link */}

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

); }