capacitor-biometric-authentication
Version:
Framework-agnostic biometric authentication library. Works with React, Vue, Angular, or vanilla JS. No providers required!
74 lines • 3.41 kB
JavaScript
var _a;
import { BiometricAuthCore } from './core/BiometricAuthCore';
// Create singleton instance
const biometricAuth = BiometricAuthCore.getInstance();
// Export the main API (provider-less, like Zustand)
const BiometricAuth = {
// Core methods
configure: (config) => biometricAuth.configure(config),
isAvailable: () => biometricAuth.isAvailable(),
getSupportedBiometrics: () => biometricAuth.getSupportedBiometrics(),
authenticate: (options) => biometricAuth.authenticate(options),
deleteCredentials: () => biometricAuth.deleteCredentials(),
hasCredentials: () => biometricAuth.hasCredentials(),
// State management
logout: () => biometricAuth.logout(),
getState: () => biometricAuth.getState(),
isAuthenticated: () => biometricAuth.isAuthenticated(),
subscribe: (callback) => biometricAuth.subscribe(callback),
// Utility methods
requireAuthentication: (callback, options) => biometricAuth.requireAuthentication(callback, options),
withAuthentication: (callback, options) => biometricAuth.withAuthentication(callback, options),
// Advanced usage
registerAdapter: (name, adapter) => biometricAuth.registerAdapter(name, adapter),
};
export { BiometricErrorCode } from './core/types';
// Export the main API as default
export default BiometricAuth;
// Also export named for flexibility
export { BiometricAuth };
// Export core classes for advanced usage
export { BiometricAuthCore } from './core/BiometricAuthCore';
export { PlatformDetector } from './core/platform-detector';
// Export adapters for those who want to use them directly
export { WebAdapter } from './adapters/WebAdapter';
export { CapacitorAdapter } from './adapters/CapacitorAdapter';
// For backward compatibility with Capacitor plugin registration
if (typeof window !== 'undefined') {
const capacitorGlobal = window;
if ((_a = capacitorGlobal.Capacitor) === null || _a === void 0 ? void 0 : _a.registerPlugin) {
// Register as a Capacitor plugin for backward compatibility
const { registerPlugin } = capacitorGlobal.Capacitor;
if (registerPlugin) {
try {
// Create a Capacitor-compatible plugin interface
const BiometricAuthPlugin = {
isAvailable: async () => ({ isAvailable: await BiometricAuth.isAvailable() }),
getSupportedBiometrics: async () => ({
biometryTypes: await BiometricAuth.getSupportedBiometrics()
}),
authenticate: async (options) => {
const result = await BiometricAuth.authenticate(options);
return {
success: result.success,
error: result.error,
biometryType: result.biometryType
};
},
deleteCredentials: async () => {
await BiometricAuth.deleteCredentials();
return {};
}
};
// Register the plugin
registerPlugin('BiometricAuth', {
web: BiometricAuthPlugin
});
}
catch (_b) {
// Ignore registration errors - not critical
}
}
}
}
//# sourceMappingURL=index.js.map