diff --git a/Dockerfile b/Dockerfile index f7154ed..9f23aea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,14 @@ FROM node:20-alpine AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . + +# Inject NEXT_PUBLIC_ vars at build time (required for client-side embedding) +ARG NEXT_PUBLIC_GUEST_EMAIL +ARG NEXT_PUBLIC_GUEST_PASSWORD + +ENV NEXT_PUBLIC_GUEST_EMAIL=$NEXT_PUBLIC_GUEST_EMAIL +ENV NEXT_PUBLIC_GUEST_PASSWORD=$NEXT_PUBLIC_GUEST_PASSWORD + RUN npm run build # 3. Run production image (Node.js server) diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx index 37a2c18..0f03978 100644 --- a/app/(auth)/login/page.tsx +++ b/app/(auth)/login/page.tsx @@ -1,15 +1,14 @@ /** * @file (auth)/login/page.tsx - * @description Client component providing a user login interface with NextAuth credentials authentication and guest login capabilities. + * @description Client component providing a user login interface utilizing the auth service. */ "use client"; import { useState } from "react"; -import { signIn } from "next-auth/react"; import { useRouter } from "next/navigation"; import Link from "next/link"; -import { getGuestCredentials } from "@/services/auth.service"; +import { getGuestCredentials, loginUser } from "@/services/auth.service"; /** * Renders the login page containing the authentication form, error handling, @@ -25,13 +24,13 @@ export default function LoginPage() { >(null); /** - * Universal sign-in handler for both manual credentials and guest login. + * 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 user email. - * @param {string} password - The user password. - * @param {"credentials" | "guest"} type - The login method type for specific loading states. - * @returns {Promise} + * @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, @@ -41,42 +40,21 @@ export default function LoginPage() { setError(null); setLoadingType(type); - const defaultErrorMessage = "An unexpected error has occurred."; + const result = await loginUser(email, password); - try { - const res = await signIn("credentials", { - email, - password, - redirect: false, - }); - - if (res?.error) { - if (res.error === "CredentialsSignin") { - setError("Incorrect email address or password."); - } else { - setError(defaultErrorMessage); - } - } else { - router.push("/summary"); - return; - } - } catch (err: any) { - if (err?.message?.includes("fetch") || err?.name === "TypeError") { - setError("Server error: API endpoint not available"); - } else { - setError(defaultErrorMessage); - } - } finally { + if (result.error) { + setError(result.error); setLoadingType(null); + } else { + router.push("/summary"); } }; /** - * Handles regular form submission. + * Handles traditional credential-based form submissions. * * @async * @param {React.SubmitEvent} e - The form submission event. - * @returns {Promise} */ const handleSubmit = async (e: React.SubmitEvent) => { e.preventDefault(); @@ -87,48 +65,33 @@ export default function LoginPage() { }; /** - * Handles quick guest login securely via Server Action. + * Fetches guest user credentials and triggers guest authentication. * * @async - * @returns {Promise} */ const handleGuestLogin = async () => { setError(null); setLoadingType("guest"); - try { - const result = await getGuestCredentials(); + const result = await getGuestCredentials(); - if ("error" in result && result.error) { - setError(result.error); - setLoadingType(null); - return; - } - - if (!result.email || !result.password) { - setError("Guest login is not configured properly."); - setLoadingType(null); - return; - } - - await handleSignIn(result.email, result.password, "guest"); - } catch (err) { - setError("Failed to initialize guest login."); + if (result.error || !result.email || !result.password) { + setError(result.error || "Guest login is not configured properly."); setLoadingType(null); + return; } + + await handleSignIn(result.email, result.password, "guest"); }; return (
- {/* Login Card Container */}
- {/* Header Section */}

Flowstate Login

Sign in to continue.

- {/* Error Notification Banner */} {error && (
)} - {/* Credentials Form */}