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
+13 -4
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({
const startPasskeyAutoFill = async () => {
try {
await authClient.signIn.passkey({
autoFill: true, autoFill: true,
fetchOptions: { fetchOptions: {
onSuccess: handleLoginSuccess, onSuccess: handleLoginSuccess,
}, },
}).catch((err) => { })
} catch (err) {
if (!isWebAuthnAbortError(err)) { if (!isWebAuthnAbortError(err)) {
console.warn("[passkey-conditional-ui]", err) console.warn("[passkey-conditional-ui]", err)
} }
}).finally(() => { } finally {
suppressPasskeyErrors = false suppressPasskeyErrors = false
}) }
}
startPasskeyAutoFill()
} }
return () => { mountedRef.current = false } return () => { mountedRef.current = false }
}, [handleLoginSuccess]) }, [handleLoginSuccess])