/** * @file RegisterPage.tsx * @description Client component providing a user registration interface for creating a new account. */ "use client"; import Link from "next/link"; import { useState } from "react"; import { useRouter } from "next/navigation"; /** * Renders the registration page featuring a sign-up form, error feedback, * and routing logic to the login page upon successful account creation. * * @returns {JSX.Element} The rendered registration page component. */ export default function RegisterPage() { const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const router = useRouter(); /** * Handles the submission of the registration form, sends user data to the API, * creates the account, auto-logins the user, and redirects to the main view on success. * * @async * @param {React.SubmitEvent} event - The form submission event. * @returns {Promise} */ async function handleSubmit(event: React.SubmitEvent) { event.preventDefault(); setError(null); setLoading(true); const formData = new FormData(event.currentTarget); const email = formData.get("email"); const password = formData.get("password"); try { // Send registration request to the API const response = await fetch("/api/auth/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password }), }); // Ensure the response is valid JSON before parsing const contentType = response.headers.get("content-type"); let data; if (contentType && contentType.includes("application/json")) { data = await response.json(); } else { throw new Error("Server error: API endpoint not available"); } // Handle non-successful status codes if (!response.ok) { throw new Error(data.message || "Something went wrong."); } // Redirect user router.push("/summary"); return; } catch (err: any) { setError(err.message); } finally { setLoading(false); } } return (
{/* Login Card Container */}
{/* Header Section */}

Create an Account

Get started with your Flowstate Workspace.

{/* Error Notification Banner */} {error && (
{error}
)} {/* Credentials Form */}
{/* Back Link Footer */}
Already have an account?{" "} Sign In
); }