Füge Unterstützung für Platform-Authentifikatoren hinzu und passe die Passkey-Registrierungsoptionen für Firefox an.
This commit is contained in:
@@ -399,6 +399,16 @@ const isFirefoxBrowser = () => {
|
||||
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 () => {
|
||||
passkeyError.value = ''
|
||||
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 mod = await import('@simplewebauthn/browser')
|
||||
|
||||
// Firefox/Linux kommt mit localDevice teils nicht klar. Für Chromium bevorzugen wir lokal.
|
||||
const registrationOptionsRequest = isFirefoxBrowser()
|
||||
? { method: 'POST' }
|
||||
: { method: 'POST', body: { preferredAuthenticatorType: 'localDevice' } }
|
||||
// localDevice nur setzen, wenn das Gerät wirklich einen Platform-Authenticator hat.
|
||||
const firefox = isFirefoxBrowser()
|
||||
const platformAvailable = await hasPlatformAuthenticator()
|
||||
const registrationOptionsRequest = (!firefox && platformAvailable)
|
||||
? { method: 'POST', body: { preferredAuthenticatorType: 'localDevice' } }
|
||||
: { method: 'POST' }
|
||||
|
||||
const res = await $fetch('/api/auth/passkeys/registration-options', registrationOptionsRequest)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user