Vereinfachung der Passkey-Registrierung durch Entfernen der bevorzugten Authentifikator-Typen und Anpassung der Fehlerbehandlung.
This commit is contained in:
@@ -400,50 +400,13 @@ const addPasskey = async () => {
|
|||||||
const name = window.prompt('Name für den Passkey (z.B. "iPhone", "Laptop"):', 'Passkey') || 'Passkey'
|
const name = window.prompt('Name für den Passkey (z.B. "iPhone", "Laptop"):', 'Passkey') || 'Passkey'
|
||||||
const mod = await import('@simplewebauthn/browser')
|
const mod = await import('@simplewebauthn/browser')
|
||||||
|
|
||||||
const userAgent = typeof navigator !== 'undefined' ? navigator.userAgent || '' : ''
|
// Kein preferredAuthenticatorType setzen → kein authenticatorAttachment gesetzt
|
||||||
const isFirefox = /Firefox\//i.test(userAgent)
|
// → 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' })
|
||||||
|
|
||||||
let platformAvailable = true
|
// @simplewebauthn/browser v13+ erwartet { optionsJSON: options }
|
||||||
if (typeof mod.platformAuthenticatorIsAvailable === 'function') {
|
const credential = await mod.startRegistration({ optionsJSON: res.options })
|
||||||
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 }
|
|
||||||
})
|
|
||||||
|
|
||||||
// @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.')
|
|
||||||
}
|
|
||||||
|
|
||||||
await $fetch('/api/auth/passkeys/register', {
|
await $fetch('/api/auth/passkeys/register', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
Reference in New Issue
Block a user