Work on face recognise

This commit is contained in:
mansi-dev
2026-01-20 23:47:52 +05:30
parent d8a10a6777
commit 6f420b88d1

View File

@@ -1,13 +1,19 @@
import React from 'react'; import React from 'react';
import { View, Text, TouchableOpacity, Alert, StyleSheet } from 'react-native'; import { View, Text, TouchableOpacity, Alert, StyleSheet } from 'react-native';
import ReactNativeBiometrics from 'react-native-biometrics'; import ReactNativeBiometrics, { BiometryTypes } from 'react-native-biometrics';
const FaceAuth = () => { const FaceAuth = () => {
const authenticate = async () => { const authenticate = async () => {
const rnBiometrics = new ReactNativeBiometrics(); try {
const rnBiometrics = new ReactNativeBiometrics({
allowDeviceCredentials: true, // Android PIN fallback
});
const { available, biometryType } = await rnBiometrics.isSensorAvailable(); const result = await rnBiometrics.isSensorAvailable();
console.log('Biometric result:', result);
const { available, biometryType } = result;
if (!available) { if (!available) {
Alert.alert('Error', 'Biometric authentication not available'); Alert.alert('Error', 'Biometric authentication not available');
@@ -15,25 +21,23 @@ const FaceAuth = () => {
} }
if ( if (
biometryType === ReactNativeBiometrics.FaceID || biometryType === BiometryTypes.FaceID ||
biometryType === ReactNativeBiometrics.Biometrics biometryType === BiometryTypes.Biometrics ||
biometryType === BiometryTypes.TouchID
) { ) {
rnBiometrics.simplePrompt({ const authResult = await rnBiometrics.simplePrompt({
promptMessage: 'Authenticate with Face ID', promptMessage: 'Authenticate to continue',
})
.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');
}); });
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');
} }
}; };
@@ -54,19 +58,13 @@ const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 1,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center' alignItems: 'center',
}, },
title: { title: {
fontSize: 20, fontSize: 20,
marginBottom: 20 marginBottom: 20,
}, },
button: { button: {
backgroundColor: '#4CAF50', backgroundColor: '#4CAF50',
padding: 15, padding: 15,
borderRadius: 8 borderRadius
},
buttonText: {
color: '#fff',
fontWeight: 'bold'
}
});