removed phone and departement as user attribute

This commit is contained in:
2025-10-10 18:22:13 +02:00
parent 6a9ddea0c5
commit e1e435a811
21 changed files with 1508 additions and 888 deletions

View File

@@ -1,109 +1,140 @@
// frontend/src/pages/Auth/Login.tsx - KORRIGIERT
import React, { useState } from 'react';
import React, { useState, useEffect } 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 [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const { login, user } = useAuth(); // user hinzugefügt für Debugging
const { login, user } = useAuth();
const { showNotification } = useNotification();
const navigate = useNavigate();
console.log('🔍 Login Component - Current user:', user);
// 🔥 NEU: Redirect wenn bereits eingeloggt
useEffect(() => {
if (user) {
console.log('✅ User already logged in, redirecting to dashboard');
navigate('/');
}
}, [user, navigate]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError('');
setLoading(true);
try {
console.log('🚀 Starting login process...');
console.log('🔐 Attempting login for:', email);
await login({ email, password });
console.log('✅ Login process completed');
// Navigation passiert automatisch durch AuthContext
// 🔥 WICHTIG: Erfolgsmeldung und Redirect
console.log('✅ Login successful, redirecting to dashboard');
showNotification({
type: 'success',
title: 'Erfolgreich angemeldet',
message: `Willkommen zurück!`
});
} catch (err: any) {
console.error('❌ Login error:', err);
setError(err.message || 'Login fehlgeschlagen');
// Navigiere zur Startseite
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);
}
};
// Wenn bereits eingeloggt, zeige Ladeanzeige
if (user) {
return (
<div style={{ textAlign: 'center', padding: '40px' }}>
<div> Weiterleiten...</div>
</div>
);
}
return (
<div style={{
maxWidth: '400px',
margin: '100px auto',
padding: '20px',
border: '1px solid #ddd',
borderRadius: '8px'
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
minHeight: '100vh',
backgroundColor: '#f5f5f5'
}}>
<h2>Anmelden</h2>
{error && (
<div style={{
color: 'red',
backgroundColor: '#ffe6e6',
padding: '10px',
borderRadius: '4px',
marginBottom: '15px'
}}>
<strong>Fehler:</strong> {error}
</div>
)}
<form onSubmit={handleSubmit}>
<div style={{ marginBottom: '15px' }}>
<label style={{ display: 'block', marginBottom: '5px' }}>
E-Mail:
<form onSubmit={handleSubmit} style={{
backgroundColor: 'white',
padding: '40px',
borderRadius: '8px',
boxShadow: '0 4px 6px rgba(0,0,0,0.1)',
width: '100%',
maxWidth: '400px'
}}>
<h2 style={{ textAlign: 'center', marginBottom: '30px' }}>Anmeldung</h2>
<div style={{ marginBottom: '20px' }}>
<label style={{ display: 'block', marginBottom: '8px', fontWeight: 'bold' }}>
E-Mail
</label>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
style={{ width: '100%', padding: '8px', border: '1px solid #ccc', borderRadius: '4px' }}
style={{
width: '100%',
padding: '10px',
border: '1px solid #ddd',
borderRadius: '4px',
fontSize: '16px'
}}
placeholder="ihre-email@example.com"
/>
</div>
<div style={{ marginBottom: '15px' }}>
<label style={{ display: 'block', marginBottom: '5px' }}>
Passwort:
<div style={{ marginBottom: '30px' }}>
<label style={{ display: 'block', marginBottom: '8px', fontWeight: 'bold' }}>
Passwort
</label>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
style={{ width: '100%', padding: '8px', border: '1px solid #ccc', borderRadius: '4px' }}
style={{
width: '100%',
padding: '10px',
border: '1px solid #ddd',
borderRadius: '4px',
fontSize: '16px'
}}
placeholder="Ihr Passwort"
/>
</div>
<button
type="submit"
<button
type="submit"
disabled={loading}
style={{
width: '100%',
padding: '10px',
style={{
width: '100%',
padding: '12px',
backgroundColor: loading ? '#ccc' : '#007bff',
color: 'white',
border: 'none',
borderRadius: '4px',
fontSize: '16px',
cursor: loading ? 'not-allowed' : 'pointer'
}}
>
{loading ? 'Anmeldung...' : 'Anmelden'}
{loading ? '⏳ Wird angemeldet...' : 'Anmelden'}
</button>
</form>
<div style={{ marginTop: '15px', textAlign: 'center' }}>
<p><strong>Test Accounts:</strong></p>
<p>admin@schichtplan.de / admin123</p>
<p>instandhalter@schichtplan.de / instandhalter123</p>
<p>user@schichtplan.de / user123</p>
</div>
</div>
);
};