/* * Registration page for creating a new user account. * * Author: Shiv * Date: April 2026 */ "use client"; import dynamic from "next/dynamic"; import Link from "next/link"; import { useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { useAuth } from "@/context/AuthContext"; const labelCls = "flex flex-col gap-[0.35rem] text-[0.9rem] font-semibold text-[#444]"; const inputCls = "px-[0.85rem] py-[0.6rem] border border-[#ddd] rounded-lg text-base outline-none transition-all focus:border-[#e68672] focus:shadow-[0_0_0_3px_rgba(230,134,114,0.2)]"; const submitBtnCls = "mt-2 py-3 bg-[#e68672] text-white border-none rounded-lg text-base font-bold cursor-pointer transition-all hover:bg-[#d4705e] active:scale-[0.98] disabled:opacity-60 disabled:cursor-not-allowed"; function resolveNextPath(candidate) { if (!candidate || !candidate.startsWith("/")) { return "/"; } if (candidate.startsWith("//") || candidate.startsWith("/login") || candidate.startsWith("/register")) { return "/"; } return candidate; } //Registration page //Collects user details, checks passwords match, then creates an account function RegisterPage() { const {register} = useAuth(); const router = useRouter(); const searchParams = useSearchParams(); const [form, setForm] = useState({ firstName: "", lastName: "", username: "", email: "", phone: "", password: "", confirmPassword: "", }); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); //Updates a single field in the form state function handleChange(e) { setForm((prev) => ({ ...prev, [e.target.name]: e.target.value })); } //Validates passwords match then submits the registration form async function handleSubmit(e) { e.preventDefault(); setError(""); if (form.password !== form.confirmPassword) { setError("Passwords do not match."); return; } setLoading(true); try { await register({ firstName: form.firstName, lastName: form.lastName, username: form.username, email: form.email, phone: form.phone, password: form.password, }); router.push(resolveNextPath(searchParams.get("next"))); } catch (err) { setError(err.message); } finally { setLoading(false); } } return (

Create Account

{error &&

{error}

}

Already have an account?{" "} Log in here

Forgot your password?{" "} Reset it here

); } export default dynamic(() => Promise.resolve(RegisterPage), { ssr: false, });