Show a scannable QR code when setting up two-factor authentication.
Deploy Development / deploy (push) Successful in 49s
Test Suite / pytest-backend (push) Successful in 46s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 16s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Failing after 5m8s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-13 08:15:51 +02:00
1 parent 2e22a7c8e0
commit 5ea225ec6b
4 files changed
+147 -94

No files matched your search

+53 -8
View File
@@ -1,17 +1,45 @@
import { useState } from 'react'
import { useEffect, useState } from 'react'
import api from '../utils/api'
/**
* TOTP einrichten: Geheimnis anzeigen, Code bestätigen, Wiederherstellungscodes einmal zeigen.
* TOTP einrichten: QR-Code und Geheimnis anzeigen, Code bestätigen, Wiederherstellungscodes einmal zeigen.
*/
export default function TotpSetupCard({ onEnabled }) {
const [secret, setSecret] = useState('')
const [otpauthUri, setOtpauthUri] = useState('')
const [qrDataUrl, setQrDataUrl] = useState('')
const [code, setCode] = useState('')
const [recoveryCodes, setRecoveryCodes] = useState([])
const [error, setError] = useState('')
const [busy, setBusy] = useState(false)
useEffect(() => {
if (!otpauthUri) {
setQrDataUrl('')
return undefined
}
let cancelled = false
import('qrcode')
.then((mod) => {
const QRCode = typeof mod.toDataURL === 'function' ? mod : mod.default
return QRCode.toDataURL(otpauthUri, {
width: 240,
margin: 2,
errorCorrectionLevel: 'M',
color: { dark: '#000000', light: '#ffffff' },
})
})
.then((url) => {
if (!cancelled) setQrDataUrl(url)
})
.catch(() => {
if (!cancelled) setQrDataUrl('')
})
return () => {
cancelled = true
}
}, [otpauthUri])
const start = async () => {
setError('')
setBusy(true)
@@ -36,6 +64,7 @@ export default function TotpSetupCard({ onEnabled }) {
if (data?.token) localStorage.setItem('authToken', data.token)
setRecoveryCodes(Array.isArray(data?.recovery_codes) ? data.recovery_codes : [])
setSecret('')
setOtpauthUri('')
setCode('')
} catch (err) {
setError(err.message || 'Code nicht akzeptiert')
@@ -48,23 +77,39 @@ export default function TotpSetupCard({ onEnabled }) {
<div className="card" style={{ marginBottom: '1rem' }}>
<h2 style={{ margin: '0 0 0.75rem', fontSize: '1.1rem' }}>Zwei-Faktor-Anmeldung</h2>
<p style={{ color: 'var(--text2)', fontSize: '0.875rem', lineHeight: 1.5 }}>
Authenticator-App (zum Beispiel Aegis, 1Password oder Microsoft Authenticator) öffnen und das
Geheimnis manuell eintragen. Den otpauth-Link nicht an Dritte geben.
Authenticator-App öffnen, ein Konto hinzufügen und den QR-Code scannen. Wenn das Scannen
nicht klappt, das Geheimnis darunter manuell eintragen.
</p>
{error ? (
<p style={{ color: 'var(--danger)', fontSize: '0.875rem' }}>{error}</p>
) : null}
{!secret && recoveryCodes.length === 0 ? (
<button type="button" className="btn btn-primary" onClick={start} disabled={busy}>
{busy ? 'Wird erzeugt…' : 'Geheimnis erzeugen'}
{busy ? 'Wird erzeugt…' : 'QR-Code erzeugen'}
</button>
) : null}
{secret ? (
<form onSubmit={confirm}>
<p style={{ fontFamily: 'ui-monospace, monospace', letterSpacing: '0.04em' }}>{secret}</p>
{otpauthUri ? (
<p style={{ fontSize: '0.75rem', wordBreak: 'break-all', color: 'var(--text3)' }}>{otpauthUri}</p>
{qrDataUrl ? (
<div
style={{
display: 'inline-block',
background: '#ffffff',
padding: 8,
borderRadius: 8,
margin: '0.25rem 0 0.85rem',
}}
>
<img
src={qrDataUrl}
alt="QR-Code zum Einrichten in der Authenticator-App"
width={240}
height={240}
style={{ display: 'block', width: 240, height: 240 }}
/>
</div>
) : null}
<p style={{ fontFamily: 'ui-monospace, monospace', letterSpacing: '0.04em', wordBreak: 'break-all' }}>{secret}</p>
<label className="form-label" htmlFor="totp-confirm-code">
Code aus der App
</label>