diff --git a/src/screen/FaceAuth.tsx b/src/screen/FaceAuth.tsx index cb47e2e..7a2c304 100644 --- a/src/screen/FaceAuth.tsx +++ b/src/screen/FaceAuth.tsx @@ -1,76 +1,17 @@ -import React from 'react'; -import { View, Text, TouchableOpacity, Alert, StyleSheet } from 'react-native'; -import ReactNativeBiometrics, { BiometryTypes } from 'react-native-biometrics'; +import ReactNativeBiometrics from 'react-native-biometrics'; -const FaceAuth = () => { +const rnBiometrics = new ReactNativeBiometrics(); - const authenticate = async () => { - try { - const rnBiometrics = new ReactNativeBiometrics({ - allowDeviceCredentials: true, // Android PIN fallback - }); +export const authenticateUser = async () => { + const { available, biometryType } = await rnBiometrics.isSensorAvailable(); - const result = await rnBiometrics.isSensorAvailable(); - console.log('Biometric result:', result); + if (!available) { + return false; + } - const { available, biometryType } = result; + const result = await rnBiometrics.simplePrompt({ + promptMessage: 'Unlock using Face ID', + }); - if (!available) { - Alert.alert('Error', 'Biometric authentication not available'); - return; - } - - if ( - biometryType === BiometryTypes.FaceID || - biometryType === BiometryTypes.Biometrics || - biometryType === BiometryTypes.TouchID - ) { - const authResult = await rnBiometrics.simplePrompt({ - promptMessage: 'Authenticate to continue', - }); - - if (authResult.success) { - Alert.alert('Success', 'Authentication successful'); - } else { - Alert.alert('Cancelled', 'Authentication cancelled'); - } - } - } catch (error) { - console.log('Biometric error:', error); - Alert.alert('Error', 'Authentication failed'); - } - }; - - return ( - - Face Authentication - - - Authenticate - - - ); + return result.success; }; - -export default FaceAuth; - -const styles = StyleSheet.create({ - container: { - flex: 1, - justifyContent: 'center', - alignItems: 'center', - }, - title: { - fontSize: 20, - marginBottom: 20, - }, - button: { - backgroundColor: '#4CAF50', - padding: 15, - borderRadius: 8, - }, - buttonText: { - color: '#fff', - fontWeight: 'bold', - }, -});