Keep recovery codes on screen and make two-factor optional.
Deploy Development / deploy (push) Successful in 51s
Test Suite / pytest-backend (push) Successful in 46s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 15s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Failing after 4m10s

Admins can replace missed codes or turn two-factor off without a forced enrollment on every login.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-13 08:03:05 +02:00
1 parent 32b28a93f3
commit 2e22a7c8e0
8 files changed
+145 -53

No files matched your search

+26 -9
View File
@@ -37,7 +37,6 @@ export default function TotpSetupCard({ onEnabled }) {
setRecoveryCodes(Array.isArray(data?.recovery_codes) ? data.recovery_codes : [])
setSecret('')
setCode('')
if (onEnabled) await onEnabled(data)
} catch (err) {
setError(err.message || 'Code nicht akzeptiert')
} finally {
@@ -85,15 +84,33 @@ export default function TotpSetupCard({ onEnabled }) {
{recoveryCodes.length > 0 ? (
<div>
<p style={{ fontSize: '0.875rem' }}>
Diese Wiederherstellungscodes jetzt sichern. Sie werden nur dieses eine Mal angezeigt.
Diese acht Codes jetzt sichern. Die Seite bleibt stehen, bis du unten bestätigst.
Ein Neuladen löscht die Anzeige. Neue Codes kannst du danach in den Einstellungen erzeugen.
</p>
<ul>
{recoveryCodes.map((item) => (
<li key={item} style={{ fontFamily: 'ui-monospace, monospace' }}>
{item}
</li>
))}
</ul>
<textarea
readOnly
rows={8}
className="form-input"
value={recoveryCodes.join('\n')}
style={{ fontFamily: 'ui-monospace, monospace', marginBottom: '0.75rem' }}
/>
<button
type="button"
className="btn btn-secondary"
style={{ marginRight: '0.5rem' }}
onClick={() => navigator.clipboard?.writeText(recoveryCodes.join('\n'))}
>
Kopieren
</button>
<button
type="button"
className="btn btn-primary"
onClick={() => {
if (onEnabled) onEnabled()
}}
>
Ich habe die Codes gespeichert
</button>
</div>
) : null}
</div>
+61 -22
View File
@@ -32,6 +32,7 @@ function AccountSettingsPage() {
const [disablePw, setDisablePw] = useState('')
const [disableCode, setDisableCode] = useState('')
const [disablingTotp, setDisablingTotp] = useState(false)
const [freshRecoveryCodes, setFreshRecoveryCodes] = useState([])
const [newPw1, setNewPw1] = useState('')
const [newPw2, setNewPw2] = useState('')
const [savingPw, setSavingPw] = useState(false)
@@ -473,21 +474,69 @@ function AccountSettingsPage() {
<h2 style={{ margin: '0 0 0.75rem', fontSize: '1.1rem' }}>Zwei-Faktor ist aktiv</h2>
<p style={{ color: 'var(--text2)', fontSize: '0.875rem' }}>
Beim Anmelden wird zusätzlich der Code aus der Authenticator-App verlangt.
Die ersten Codes lassen sich nicht erneut anzeigen. Hier entstehen neue, die alten gelten danach nicht mehr.
</p>
{user?.role === 'admin' || user?.role === 'superadmin' ? (
<p style={{ color: 'var(--text2)', fontSize: '0.875rem' }}>
Für Plattform-Admins bleibt das so.
</p>
) : (
<form
onSubmit={async (e) => {
e.preventDefault()
{freshRecoveryCodes.length > 0 ? (
<div style={{ marginBottom: '1rem' }}>
<textarea
readOnly
rows={8}
className="form-input"
value={freshRecoveryCodes.join('\n')}
style={{ fontFamily: 'ui-monospace, monospace', marginBottom: '0.75rem' }}
/>
<button
type="button"
className="btn btn-secondary"
style={{ marginRight: '0.5rem' }}
onClick={() => navigator.clipboard?.writeText(freshRecoveryCodes.join('\n'))}
>
Kopieren
</button>
<button type="button" className="btn btn-primary" onClick={() => setFreshRecoveryCodes([])}>
Ich habe die Codes gespeichert
</button>
</div>
) : null}
<form
onSubmit={async (e) => {
e.preventDefault()
setDisablingTotp(true)
try {
const data = await api.regenerateRecoveryCodes(disablePw, disableCode.trim())
setFreshRecoveryCodes(Array.isArray(data?.recovery_codes) ? data.recovery_codes : [])
setDisableCode('')
showOk('Neue Wiederherstellungscodes sind da. Die bisherigen gelten nicht mehr.')
} catch (err) {
showErr(err.message || 'Neue Codes konnten nicht erzeugt werden')
} finally {
setDisablingTotp(false)
}
}}
>
<div className="form-row" style={{ marginBottom: '0.75rem' }}>
<label className="form-label" htmlFor="totp-off-pw">Aktuelles Passwort</label>
<input id="totp-off-pw" type="password" className="form-input" value={disablePw} onChange={(e) => setDisablePw(e.target.value)} autoComplete="current-password" />
</div>
<div className="form-row" style={{ marginBottom: '0.75rem' }}>
<label className="form-label" htmlFor="totp-off-code">Aktueller Code aus der App</label>
<input id="totp-off-code" className="form-input" value={disableCode} onChange={(e) => setDisableCode(e.target.value)} autoComplete="one-time-code" />
</div>
<button type="submit" className="btn btn-secondary" disabled={disablingTotp} style={{ marginRight: '0.5rem' }}>
{disablingTotp ? 'Bitte warten…' : 'Neue Wiederherstellungscodes'}
</button>
<button
type="button"
className="btn btn-secondary"
disabled={disablingTotp}
onClick={async () => {
setDisablingTotp(true)
try {
await api.disableTotp(disablePw, disableCode.trim())
setDisablePw('')
setDisableCode('')
showOk('Zwei-Faktor ist aus.')
setFreshRecoveryCodes([])
showOk('Zwei-Faktor ist aus. Den Eintrag in der Authenticator-App kannst du löschen.')
await checkAuth()
} catch (err) {
showErr(err.message || 'Abschalten fehlgeschlagen')
@@ -496,19 +545,9 @@ function AccountSettingsPage() {
}
}}
>
<div className="form-row" style={{ marginBottom: '0.75rem' }}>
<label className="form-label" htmlFor="totp-off-pw">Aktuelles Passwort</label>
<input id="totp-off-pw" type="password" className="form-input" value={disablePw} onChange={(e) => setDisablePw(e.target.value)} autoComplete="current-password" />
</div>
<div className="form-row" style={{ marginBottom: '0.75rem' }}>
<label className="form-label" htmlFor="totp-off-code">Code oder Wiederherstellungscode</label>
<input id="totp-off-code" className="form-input" value={disableCode} onChange={(e) => setDisableCode(e.target.value)} autoComplete="one-time-code" />
</div>
<button type="submit" className="btn btn-secondary" disabled={disablingTotp}>
{disablingTotp ? 'Wird gespeichert…' : 'Zwei-Faktor ausschalten'}
</button>
</form>
)}
Zwei-Faktor ausschalten
</button>
</form>
</div>
) : (
<TotpSetupCard onEnabled={() => checkAuth()} />
+8
View File
@@ -47,6 +47,13 @@ export async function confirmTotp(code) {
})
}
export async function regenerateRecoveryCodes(currentPassword, code) {
return request('/api/auth/totp/recovery-codes', {
method: 'POST',
body: JSON.stringify({ current_password: currentPassword, code }),
})
}
export async function disableTotp(currentPassword, code) {
return request('/api/auth/totp/disable', {
method: 'POST',
@@ -1032,6 +1039,7 @@ export const api = {
getTotpStatus,
setupTotp,
confirmTotp,
regenerateRecoveryCodes,
disableTotp,
issueMediaGrant,
register,