Improve passkey registration error handling and options serialization
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 44s

Enhance the registration process by adding error handling for the WebAuthn startRegistration method and ensuring the presence of required options. Include debug logging for received options and serialize the options correctly before returning them in the API response, improving robustness and clarity in the registration flow.
This commit is contained in:
Torsten Schulz (local)
2026-01-07 21:30:13 +01:00
parent b34a6fc155
commit bb985ddc8f
2 changed files with 32 additions and 5 deletions

View File

@@ -339,15 +339,28 @@ const handleRegisterWithPasskey = async () => {
}
// Debug: Prüfe Options-Struktur
if (!pre.options.challenge) {
console.log('Received options:', {
hasChallenge: !!pre.options?.challenge,
hasRp: !!pre.options?.rp,
hasUser: !!pre.options?.user,
timeout: pre.options?.timeout
})
if (!pre.options || !pre.options.challenge) {
console.error('Options fehlen challenge:', pre.options)
throw new Error('Ungültige WebAuthn-Options vom Server')
}
const mod = await import('@simplewebauthn/browser')
// startRegistration erwartet die Options direkt, nicht verschachtelt
// startRegistration erwartet die Options direkt
// @simplewebauthn/browser v13+ erwartet die Options direkt
const credential = await mod.startRegistration(pre.options)
let credential
try {
credential = await mod.startRegistration(pre.options)
} catch (webauthnError) {
console.error('WebAuthn startRegistration error:', webauthnError)
throw new Error('Passkey-Registrierung fehlgeschlagen: ' + (webauthnError?.message || 'Unbekannter Fehler'))
}
const response = await $fetch('/api/auth/register-passkey', {
method: 'POST',