'use client' import { useState } from 'react' import { createAuthClient } from 'better-auth/react' const authClient = createAuthClient({ baseURL: typeof window !== 'undefined' ? window.location.origin : (process.env.NEXT_PUBLIC_APP_URL ?? 'http://localhost:3032'), }) export default function PasswortAendernPage() { const [oldPassword, setOldPassword] = useState('') const [newPassword, setNewPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState('') async function handleSubmit(e: React.FormEvent) { e.preventDefault() setError('') if (newPassword !== confirmPassword) { setError('Die neuen Passwörter stimmen nicht überein.') return } if (newPassword.length < 8) { setError('Das neue Passwort muss mindestens 8 Zeichen haben.') return } if (newPassword === oldPassword) { setError('Das neue Passwort muss sich vom alten unterscheiden.') return } setLoading(true) const result = await authClient.changePassword({ currentPassword: oldPassword, newPassword, revokeOtherSessions: false, }) if (result.error) { setLoading(false) setError(result.error.message ?? 'Das alte Passwort ist falsch.') return } // Mark mustChangePassword as done await fetch('/api/auth/clear-must-change-password', { method: 'POST' }) window.location.href = '/dashboard' } return (

Passwort ändern

Bitte legen Sie jetzt Ihr persönliches Passwort fest.

Aus Sicherheitsgründen müssen Sie das temporäre Passwort durch ein eigenes ersetzen.
setOldPassword(e.target.value)} placeholder="Temporäres Passwort" className="w-full px-3 py-2.5 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent" />
setNewPassword(e.target.value)} placeholder="Mindestens 8 Zeichen" className="w-full px-3 py-2.5 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent" />
setConfirmPassword(e.target.value)} placeholder="Passwort wiederholen" className="w-full px-3 py-2.5 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent" />
{error && (

{error}

)}
) }