Files
Netcatty/application/state/useWebAuthnBackend.ts
T
bincxz e91940005b Adds WebAuthn browser fallback for macOS Touch ID
Implements a browser-based WebAuthn fallback for biometric key creation and authentication, improving reliability of Touch ID prompts on macOS, especially when Electron's embedded WebAuthn flow fails. Integrates helper flows, IPC, and UI feedback to guide users through the browser prompt and ensure cross-platform consistency.
2025-12-13 13:39:01 +08:00

34 lines
1.1 KiB
TypeScript

import { useCallback } from "react";
import { netcattyBridge } from "../../infrastructure/services/netcattyBridge";
export const useWebAuthnBackend = () => {
const hasBrowserWebAuthn = useCallback(() => {
return !!netcattyBridge.get()?.webauthnCreateCredentialInBrowser;
}, []);
const createCredentialInBrowser = useCallback(
async (options: WebAuthnBrowserCreateOptions) => {
const bridge = netcattyBridge.get();
if (!bridge?.webauthnCreateCredentialInBrowser) {
throw new Error("webauthnCreateCredentialInBrowser unavailable");
}
return bridge.webauthnCreateCredentialInBrowser(options);
},
[],
);
const getAssertionInBrowser = useCallback(
async (options: WebAuthnBrowserGetOptions) => {
const bridge = netcattyBridge.get();
if (!bridge?.webauthnGetAssertionInBrowser) {
throw new Error("webauthnGetAssertionInBrowser unavailable");
}
return bridge.webauthnGetAssertionInBrowser(options);
},
[],
);
return { hasBrowserWebAuthn, createCredentialInBrowser, getAssertionInBrowser };
};