Improve passkey registration error handling and options serialization
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 44s
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:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user