diff --git a/src/screen/FaceAuth.tsx b/src/screen/FaceAuth.tsx new file mode 100644 index 0000000..4c323ea --- /dev/null +++ b/src/screen/FaceAuth.tsx @@ -0,0 +1,72 @@ +import React from 'react'; +import { View, Text, TouchableOpacity, Alert, StyleSheet } from 'react-native'; +import ReactNativeBiometrics from 'react-native-biometrics'; + +const FaceAuth = () => { + + const authenticate = async () => { + const rnBiometrics = new ReactNativeBiometrics(); + + const { available, biometryType } = await rnBiometrics.isSensorAvailable(); + + if (!available) { + Alert.alert('Error', 'Biometric authentication not available'); + return; + } + + if ( + biometryType === ReactNativeBiometrics.FaceID || + biometryType === ReactNativeBiometrics.Biometrics + ) { + rnBiometrics.simplePrompt({ + promptMessage: 'Authenticate with Face ID', + }) + .then((resultObject) => { + const { success } = resultObject; + + if (success) { + Alert.alert('Success', 'Face authentication successful'); + // 👉 navigate / unlock app / allow action + } else { + Alert.alert('Cancelled', 'User cancelled authentication'); + } + }) + .catch(() => { + Alert.alert('Error', 'Authentication failed'); + }); + } + }; + + return ( + + Face Authentication + + + Authenticate + + + ); +}; + +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' + } +});