import * as LocalAuthentication from "expo-local-authentication"; class BiometricsService { async isBiometricSupported(): Promise { try { const compatible = await LocalAuthentication.hasHardwareAsync(); const enrolled = await LocalAuthentication.isEnrolledAsync(); return compatible && enrolled; } catch (error) { console.error("Biometric support check failed:", error); return false; } } async getBiometricType(): Promise { try { const types = await LocalAuthentication.supportedAuthenticationTypesAsync(); return types; } catch (error) { console.error("Get biometric type failed:", error); return []; } } async authenticateWithBiometrics(): Promise { try { const biometryType = await this.isBiometricSupported(); if (!biometryType) { throw new Error("Biometric authentication not supported"); } const result = await LocalAuthentication.authenticateAsync({ promptMessage: "Biometrische Authentifizierung", cancelLabel: "Abbrechen", fallbackLabel: "Passcode verwenden", requireConfirmation: true, }); return result.success; } catch (error) { console.error("Biometric authentication failed:", error); return false; } } async showBiometricPrompt( reason: string = "Für sicheren Zugang authentifizieren" ): Promise { try { const isSupported = await this.isBiometricSupported(); if (!isSupported) { throw new Error("Biometric authentication not available"); } return await this.authenticateWithBiometrics(); } catch (error) { console.error("Biometric prompt failed:", error); return false; } } } export default new BiometricsService();