// frontend/src/pages/Auth/Login.tsx - UPDATED PASSWORD SECTION import React, { useState, useEffect, useRef } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../../contexts/AuthContext'; import { useNotification } from '../../contexts/NotificationContext'; const Login: React.FC = () => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); const { login, user } = useAuth(); const { showNotification } = useNotification(); const navigate = useNavigate(); const holdTimeoutRef = useRef(null); const passwordInputRef = useRef(null); useEffect(() => { if (user) { console.log('✅ User already logged in, redirecting to dashboard'); navigate('/'); } }, [user, navigate]); // Cleanup timeouts on unmount useEffect(() => { return () => { if (holdTimeoutRef.current) { clearTimeout(holdTimeoutRef.current); } }; }, []); const handleMouseDown = () => { // Start timeout to show password after a brief delay (300ms) holdTimeoutRef.current = setTimeout(() => { setShowPassword(true); }, 300); }; const handleMouseUp = () => { // Clear the timeout if user releases before delay completes if (holdTimeoutRef.current) { clearTimeout(holdTimeoutRef.current); holdTimeoutRef.current = null; } // Always hide password on release setShowPassword(false); }; const handleTouchStart = (e: React.TouchEvent) => { e.preventDefault(); // Prevent context menu on mobile handleMouseDown(); }; const handleTouchEnd = (e: React.TouchEvent) => { e.preventDefault(); handleMouseUp(); }; // Prevent context menu on long press const handleContextMenu = (e: React.MouseEvent) => { e.preventDefault(); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); try { console.log('🔐 Attempting login for:', email); await login({ email, password }); console.log('✅ Login successful, redirecting to dashboard'); showNotification({ type: 'success', title: 'Erfolgreich angemeldet', message: `Willkommen zurück!` }); navigate('/'); } catch (error: any) { console.error('❌ Login error:', error); showNotification({ type: 'error', title: 'Anmeldung fehlgeschlagen', message: error.message || 'Bitte überprüfen Sie Ihre Anmeldedaten' }); } finally { setLoading(false); } }; if (user) { return (
⏳ Weiterleiten...
); } return (

Anmeldung

setEmail(e.target.value)} required style={{ width: '100%', padding: '10px', border: '1px solid #ddd', borderRadius: '4px', fontSize: '16px' }} placeholder="ihre-email@example.com" />
setPassword(e.target.value)} required style={{ width: '100%', padding: '10px', paddingRight: '10px', border: '1px solid #ddd', borderRadius: '4px', fontSize: '16px' }} placeholder="Ihr Passwort" />
); }; export default Login;