Füge Unterstützung für Platform-Authentifikatoren hinzu und passe die Passkey-Registrierungsoptionen für Firefox an.
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 1m56s

This commit is contained in:
Torsten Schulz (local)
2026-05-15 14:01:18 +02:00
parent 4521ce002e
commit dcc4055eca

View File

@@ -399,6 +399,16 @@ const isFirefoxBrowser = () => {
return /firefox/i.test(ua) return /firefox/i.test(ua)
} }
const hasPlatformAuthenticator = async () => {
if (!process.client || !window.PublicKeyCredential) return false
if (typeof window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable !== 'function') return false
try {
return await window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
} catch {
return false
}
}
const addPasskey = async () => { const addPasskey = async () => {
passkeyError.value = '' passkeyError.value = ''
passkeyLoading.value = true passkeyLoading.value = true
@@ -406,10 +416,12 @@ 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')
// Firefox/Linux kommt mit localDevice teils nicht klar. Für Chromium bevorzugen wir lokal. // localDevice nur setzen, wenn das Gerät wirklich einen Platform-Authenticator hat.
const registrationOptionsRequest = isFirefoxBrowser() const firefox = isFirefoxBrowser()
? { method: 'POST' } const platformAvailable = await hasPlatformAuthenticator()
: { method: 'POST', body: { preferredAuthenticatorType: 'localDevice' } } const registrationOptionsRequest = (!firefox && platformAvailable)
? { method: 'POST', body: { preferredAuthenticatorType: 'localDevice' } }
: { method: 'POST' }
const res = await $fetch('/api/auth/passkeys/registration-options', registrationOptionsRequest) const res = await $fetch('/api/auth/passkeys/registration-options', registrationOptionsRequest)