added password unveiling on login

This commit is contained in:
2025-10-23 19:17:51 +02:00
parent b60e5ccdd2
commit b9a88bce1c

View File

@@ -1,18 +1,21 @@
// frontend/src/pages/Auth/Login.tsx - KORRIGIERT // frontend/src/pages/Auth/Login.tsx - UPDATED PASSWORD SECTION
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { useAuth } from '../../contexts/AuthContext'; import { useAuth } from '../../contexts/AuthContext';
import { useNotification } from '../../contexts/NotificationContext'; import { useNotification } from '../../contexts/NotificationContext';
import { employeeService } from '../../services/employeeService';
const Login: React.FC = () => { const Login: React.FC = () => {
const [email, setEmail] = useState(''); const [email, setEmail] = useState('');
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const [showPassword, setShowPassword] = useState(false);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const { login, user } = useAuth(); const { login, user } = useAuth();
const { showNotification } = useNotification(); const { showNotification } = useNotification();
const navigate = useNavigate(); const navigate = useNavigate();
const holdTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const passwordInputRef = useRef<HTMLInputElement>(null);
useEffect(() => { useEffect(() => {
if (user) { if (user) {
console.log('✅ User already logged in, redirecting to dashboard'); console.log('✅ User already logged in, redirecting to dashboard');
@@ -20,6 +23,47 @@ const Login: React.FC = () => {
} }
}, [user, 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) => { const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
setLoading(true); setLoading(true);
@@ -35,7 +79,6 @@ const Login: React.FC = () => {
message: `Willkommen zurück!` message: `Willkommen zurück!`
}); });
// Navigiere zur Startseite
navigate('/'); navigate('/');
} catch (error: any) { } catch (error: any) {
@@ -50,7 +93,6 @@ const Login: React.FC = () => {
} }
}; };
// Wenn bereits eingeloggt, zeige Ladeanzeige
if (user) { if (user) {
return ( return (
<div style={{ textAlign: 'center', padding: '40px' }}> <div style={{ textAlign: 'center', padding: '40px' }}>
@@ -101,20 +143,53 @@ const Login: React.FC = () => {
<label style={{ display: 'block', marginBottom: '8px', fontWeight: 'bold' }}> <label style={{ display: 'block', marginBottom: '8px', fontWeight: 'bold' }}>
Passwort Passwort
</label> </label>
<input <div style={{ position: 'relative' }}>
type="password" <input
value={password} ref={passwordInputRef}
onChange={(e) => setPassword(e.target.value)} type={showPassword ? 'text' : 'password'}
required value={password}
style={{ onChange={(e) => setPassword(e.target.value)}
width: '94.5%', required
padding: '10px', style={{
border: '1px solid #ddd', width: '94.5%',
borderRadius: '4px', padding: '10px',
fontSize: '16px' paddingRight: '10px',
}} border: '1px solid #ddd',
placeholder="Ihr Passwort" borderRadius: '4px',
/> fontSize: '16px'
}}
placeholder="Ihr Passwort"
/>
<button
type="button"
onMouseDown={handleMouseDown}
onMouseUp={handleMouseUp}
onMouseLeave={handleMouseUp} // Handle mouse leaving while pressed
onTouchStart={handleTouchStart}
onTouchEnd={handleTouchEnd}
onTouchCancel={handleTouchEnd} // Handle touch cancellation
onContextMenu={handleContextMenu}
style={{
position: 'absolute',
right: '10px',
top: '50%',
transform: 'translateY(-50%)',
background: 'none',
border: 'none',
cursor: 'pointer',
padding: '1px',
borderRadius: '1px',
backgroundColor: showPassword ? '#e0e0e0' : 'transparent',
transition: 'background-color 0.2s',
userSelect: 'none',
WebkitUserSelect: 'none',
touchAction: 'manipulation'
}}
title="Gedrückt halten zum Anzeigen des Passworts"
>
{showPassword ? '👁' : '👁'}
</button>
</div>
</div> </div>
<button <button