/** * @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 { loginAsGuest, 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 [loadingType, setLoadingType] = useState< "credentials" | "guest" | null >(null); /** * 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, "credentials"); }; /** * Authenticates the user with provided credentials and redirects upon success. * */ const handleSignIn = async ( email: string, password: string, type: "credentials" | "guest", ) => { setError(null); setLoadingType(type); const result = await loginUser(email, password); if (result.error) { setError(result.error); setLoadingType(null); } else { router.push("/"); } }; /** * Triggers secure guest authentication via the backend service. * * @async */ 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 */}
or
{/* Footer Link */}

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

); }