fix: prevent passkey conditional ui unhandled rejection blocking login

This commit is contained in:
2026-06-28 05:55:00 +08:00
parent 4cf8a42742
commit eaa7c85e09
+20 -11
View File
@@ -57,23 +57,32 @@ export default function LoginForm() {
// Preload passkeys for conditional UI — must be called on mount when // Preload passkeys for conditional UI — must be called on mount when
// both email + password fields are in the DOM. // both email + password fields are in the DOM.
// Note: WebAuthn conditional mediation can throw NetworkError on pages
// with self-signed certs (common in dev). We catch and suppress it.
useEffect(() => { useEffect(() => {
mountedRef.current = true mountedRef.current = true
if ("PublicKeyCredential" in window && !passkeyInitiatedRef.current) { if ("PublicKeyCredential" in window && !passkeyInitiatedRef.current) {
passkeyInitiatedRef.current = true passkeyInitiatedRef.current = true
suppressPasskeyErrors = true suppressPasskeyErrors = true
authClient.signIn.passkey({
autoFill: true, const startPasskeyAutoFill = async () => {
fetchOptions: { try {
onSuccess: handleLoginSuccess, await authClient.signIn.passkey({
}, autoFill: true,
}).catch((err) => { fetchOptions: {
if (!isWebAuthnAbortError(err)) { onSuccess: handleLoginSuccess,
console.warn("[passkey-conditional-ui]", err) },
})
} catch (err) {
if (!isWebAuthnAbortError(err)) {
console.warn("[passkey-conditional-ui]", err)
}
} finally {
suppressPasskeyErrors = false
} }
}).finally(() => { }
suppressPasskeyErrors = false
}) startPasskeyAutoFill()
} }
return () => { mountedRef.current = false } return () => { mountedRef.current = false }
}, [handleLoginSuccess]) }, [handleLoginSuccess])