diff --git a/src/client/components/login-form.tsx b/src/client/components/login-form.tsx index 1213874..7ab8f54 100644 --- a/src/client/components/login-form.tsx +++ b/src/client/components/login-form.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import { useAuth } from "@/client/components/auth-provider"; export function LoginForm() { @@ -6,9 +6,27 @@ export function LoginForm() { const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [isLoading, setIsLoading] = useState(false); + const [isInitialized, setIsInitialized] = useState(false); const { login } = useAuth(); + // Load saved username from localStorage on mount + useEffect(() => { + const savedUsername = localStorage.getItem("loginForm_username"); + if (savedUsername) setUsername(savedUsername); + setIsInitialized(true); + }, []); + + // Save username to localStorage when it changes (after initial load) + useEffect(() => { + if (!isInitialized) return; + if (username) { + localStorage.setItem("loginForm_username", username); + } else { + localStorage.removeItem("loginForm_username"); + } + }, [username, isInitialized]); + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError("");