feat: Login-Formular merkt sich Benutzername
- Benutzername wird in localStorage gespeichert - Beim nächsten Login automatisch ausgefüllt - Verbessert UX für wiederkehrende Logins
This commit is contained in:
@@ -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("");
|
||||
|
Reference in New Issue
Block a user