From 516e26f5ca72f2db724fd68584663c0732c77f77 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 6 Dec 2025 18:38:57 +0900 Subject: feat(client): implement Login page with form validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add login form with username/password fields, error handling, and automatic redirect when already authenticated. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/client/pages/LoginPage.tsx | 76 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) (limited to 'src/client/pages/LoginPage.tsx') diff --git a/src/client/pages/LoginPage.tsx b/src/client/pages/LoginPage.tsx index 459e2ce..f72a6da 100644 --- a/src/client/pages/LoginPage.tsx +++ b/src/client/pages/LoginPage.tsx @@ -1,8 +1,82 @@ +import { type FormEvent, useEffect, useState } from "react"; +import { Link, useLocation } from "wouter"; +import { ApiClientError, useAuth } from "../stores"; + export function LoginPage() { + const [, navigate] = useLocation(); + const { login, isAuthenticated } = useAuth(); + const [username, setUsername] = useState(""); + const [password, setPassword] = 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); + + setIsSubmitting(true); + + try { + await login(username, password); + navigate("/", { replace: true }); + } catch (err) { + if (err instanceof ApiClientError) { + setError(err.message); + } else { + setError("Login failed. Please try again."); + } + } finally { + setIsSubmitting(false); + } + }; + return (

Login

-

Login page coming soon

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

+ Don't have an account? Register +

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