import { useState } from 'react'; import { useAuth } from '../context/AuthContext'; import { updateCredentials } from '../auth'; export default function Profile() { const { token, user: authUser, loginUser } = useAuth(); const [currentPassword, setCurrentPassword] = useState(''); const [newUsername, setNewUsername] = useState(''); const [newPassword, setNewPassword] = useState(''); const [saving, setSaving] = useState(false); const [error, setError] = useState(''); const [success, setSuccess] = useState(''); const handleSubmit = async (e) => { e.preventDefault(); setSaving(true); setError(''); setSuccess(''); try { const data = await updateCredentials(token, { currentPassword, newUsername: newUsername || undefined, newPassword: newPassword || undefined, }); loginUser(data.user, data.token); setCurrentPassword(''); setNewUsername(''); setNewPassword(''); setSuccess('Daten erfolgreich geändert!'); } catch (err) { setError(err.message); } setSaving(false); }; return (

Profil

Angemeldet als {authUser?.username} {authUser?.is_admin && Admin}

{error && (
{error}
)} {success && (
{success}
)}
setCurrentPassword(e.target.value)} placeholder="Aktuelles Passwort eingeben" required className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" />
setNewUsername(e.target.value)} placeholder="Neuen Benutzernamen wählen" className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" />
setNewPassword(e.target.value)} placeholder="Mindestens 6 Zeichen" className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" />
); }