From 516e26f5ca72f2db724fd68584663c0732c77f77 Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
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 <noreply@anthropic.com>
---
 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<string | null>(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 (
 		<div>
 			<h1>Login</h1>
-			<p>Login page coming soon</p>
+			<form onSubmit={handleSubmit}>
+				{error && (
+					<div role="alert" style={{ color: "red" }}>
+						{error}
+					</div>
+				)}
+				<div>
+					<label htmlFor="username">Username</label>
+					<input
+						id="username"
+						type="text"
+						value={username}
+						onChange={(e) => setUsername(e.target.value)}
+						required
+						autoComplete="username"
+						disabled={isSubmitting}
+					/>
+				</div>
+				<div>
+					<label htmlFor="password">Password</label>
+					<input
+						id="password"
+						type="password"
+						value={password}
+						onChange={(e) => setPassword(e.target.value)}
+						required
+						autoComplete="current-password"
+						disabled={isSubmitting}
+					/>
+				</div>
+				<button type="submit" disabled={isSubmitting}>
+					{isSubmitting ? "Logging in..." : "Login"}
+				</button>
+			</form>
+			<p>
+				Don't have an account? <Link href="/register">Register</Link>
+			</p>
 		</div>
 	);
 }
-- 
cgit v1.2.3-70-g09d2

