'use client'; import Link from "next/link"; import { useState, useEffect } from "react"; import { register } from "../../lib/client/register"; import { useRouter } from "next/navigation" export default function RegisterPage() { const [name, setName] = useState(""); // creating state objects and getting setters const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [error, setError] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const router = useRouter(); const handleSubmit = async (e: React.SubmitEvent) => { // event object from form element e.preventDefault(); // stops default submission to send through the js instead setError(""); // clear state if (password !== confirmPassword) { setError("Passwords do not match") return; } if (password.length < 16 || password === password.toLowerCase() || password === password.toUpperCase()) { // rejects password if its not 16+ characters or if its all in the same case setError("Password must be at least 16 characters and a mix of lower and upper case. To keep your account secure also include special characters and dont use predictable phrases.") return; } setIsSubmitting(true); // once password is valid try { await register({ email, password, name }) router.push("/login?registered=true") } catch (error) { setError(error instanceof Error ? error.message : "Registration failed") } finally { setIsSubmitting(false); } } // useEffect(() => { // on page load // if (!isLoading && isAuthenticated) { // router.push("/") // } // },[isLoading, isAuthenticated, router]) return ( <>

Create Account

{error && (
{error}
)} {" "}
setName(e.target.value)} />
setEmail(e.target.value)} required />
setPassword(e.target.value)} required />
setConfirmPassword(e.target.value)} required />
) };