/** * @file (auth)/login/page.tsx * @description Client component providing a user login interface utilizing the auth service. */ "use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { loginAsGuest, loginUser } from "@/services/auth.service"; /** * Renders the login page containing the authentication form, error handling, * and navigation links for user sign-in. * * @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); /** * Performs user authentication via email and password using the auth service. * Redirects to the summary page upon success or sets an error message on failure. * * @async * @param {string} email - The email address for login. * @param {string} password - The account password. * @param {"credentials" | "guest"} type - The authentication trigger source type. */ 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("/summary"); } }; /** * Handles traditional credential-based form submissions. * * @async * @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"); }; /** * 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("/summary"); }; return (

Flowstate Login

Sign in to continue.

{error && (
{error}
)}
or
Don't have an account yet?{" "} Register
); }