From a2569837aa07ef48f27884fc2869b5be47087a4e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 6 Dec 2025 18:36:10 +0900 Subject: feat(client): implement Register page with form validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add functional registration form with: - Username and password fields with confirm password - Client-side validation (password match, minimum length) - Error display for API failures - Redirect to home when already authenticated - Loading state during submission 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/client/pages/RegisterPage.tsx | 99 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) (limited to 'src/client/pages/RegisterPage.tsx') diff --git a/src/client/pages/RegisterPage.tsx b/src/client/pages/RegisterPage.tsx index a7fbb59..e6783bd 100644 --- a/src/client/pages/RegisterPage.tsx +++ b/src/client/pages/RegisterPage.tsx @@ -1,8 +1,105 @@ +import { type FormEvent, useEffect, useState } from "react"; +import { Link, useLocation } from "wouter"; +import { ApiClientError, useAuth } from "../stores"; + export function RegisterPage() { + const [, navigate] = useLocation(); + const { register, isAuthenticated } = useAuth(); + const [username, setUsername] = useState(""); + const [password, setPassword] = useState(""); + const [confirmPassword, setConfirmPassword] = useState(""); + const [error, setError] = useState(null); + const [isSubmitting, setIsSubmitting] = useState(false); + + // Redirect if already authenticated + useEffect(() => { + if (isAuthenticated) { + navigate("/", { replace: true }); + } + }, [isAuthenticated, navigate]); + + const handleSubmit = async (e: FormEvent) => { + e.preventDefault(); + setError(null); + + if (password !== confirmPassword) { + setError("Passwords do not match"); + return; + } + + if (password.length < 8) { + setError("Password must be at least 8 characters"); + return; + } + + setIsSubmitting(true); + + try { + await register(username, password); + navigate("/", { replace: true }); + } catch (err) { + if (err instanceof ApiClientError) { + setError(err.message); + } else { + setError("Registration failed. Please try again."); + } + } finally { + setIsSubmitting(false); + } + }; + return (

Register

-

Registration page coming soon

+
+ {error && ( +
+ {error} +
+ )} +
+ + setUsername(e.target.value)} + required + autoComplete="username" + disabled={isSubmitting} + /> +
+
+ + setPassword(e.target.value)} + required + autoComplete="new-password" + disabled={isSubmitting} + /> +
+
+ + setConfirmPassword(e.target.value)} + required + autoComplete="new-password" + disabled={isSubmitting} + /> +
+ +
+

+ Already have an account? Login +

); } -- cgit v1.2.3-70-g09d2