Vereinfachung der Passkey-Registrierung durch Entfernen der bevorzugten Authentifikator-Typen und Anpassung der Fehlerbehandlung.
All checks were successful
Code Analysis and Production Deploy / analyze (push) Has been skipped
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Successful in 1m52s

This commit is contained in:
Torsten Schulz (local)
2026-05-15 13:36:53 +02:00
parent 48f8b46e57
commit 842a516ce6

View File

@@ -400,50 +400,13 @@ const addPasskey = async () => {
const name = window.prompt('Name für den Passkey (z.B. "iPhone", "Laptop"):', 'Passkey') || 'Passkey'
const mod = await import('@simplewebauthn/browser')
const userAgent = typeof navigator !== 'undefined' ? navigator.userAgent || '' : ''
const isFirefox = /Firefox\//i.test(userAgent)
let platformAvailable = true
if (typeof mod.platformAuthenticatorIsAvailable === 'function') {
try {
platformAvailable = await mod.platformAuthenticatorIsAvailable()
} catch {
platformAvailable = true
}
}
const preferenceChain = []
if (isFirefox) {
// Firefox kann unter Linux Passkeys browserseitig verwalten, auch wenn kein
// klassischer Platform-Authenticator erkannt wird.
preferenceChain.push('localDevice', 'remoteDevice')
} else if (!platformAvailable) {
preferenceChain.push('remoteDevice', 'localDevice')
} else {
preferenceChain.push('localDevice')
}
let credential = null
let lastError = null
for (const preferredAuthenticatorType of preferenceChain) {
try {
const res = await $fetch('/api/auth/passkeys/registration-options', {
method: 'POST',
body: { preferredAuthenticatorType }
})
// Kein preferredAuthenticatorType setzen → kein authenticatorAttachment gesetzt
// → Browser (inkl. Firefox) wählt selbst: interner Passkey-Store, Smartphone oder Security Key
// Firefox speichert den Passkey dann intern wie ein Passwort (kein Hardware-Key nötig)
const res = await $fetch('/api/auth/passkeys/registration-options', { method: 'POST' })
// @simplewebauthn/browser v13+ erwartet { optionsJSON: options }
credential = await mod.startRegistration({ optionsJSON: res.options })
break
} catch (err) {
lastError = err
}
}
if (!credential) {
throw lastError || new Error('Passkey konnte nicht erstellt werden.')
}
const credential = await mod.startRegistration({ optionsJSON: res.options })
await $fetch('/api/auth/passkeys/register', {
method: 'POST',