Work on face recognise
This commit is contained in:
@@ -1,39 +1,43 @@
|
||||
import React from 'react';
|
||||
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 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);
|
||||
|
||||
if (!available) {
|
||||
Alert.alert('Error', 'Biometric authentication not available');
|
||||
return;
|
||||
}
|
||||
const { available, biometryType } = result;
|
||||
|
||||
if (
|
||||
biometryType === ReactNativeBiometrics.FaceID ||
|
||||
biometryType === ReactNativeBiometrics.Biometrics
|
||||
) {
|
||||
rnBiometrics.simplePrompt({
|
||||
promptMessage: 'Authenticate with Face ID',
|
||||
})
|
||||
.then((resultObject) => {
|
||||
const { success } = resultObject;
|
||||
if (!available) {
|
||||
Alert.alert('Error', 'Biometric authentication not available');
|
||||
return;
|
||||
}
|
||||
|
||||
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 (
|
||||
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');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -54,19 +58,13 @@ const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center'
|
||||
alignItems: 'center',
|
||||
},
|
||||
title: {
|
||||
fontSize: 20,
|
||||
marginBottom: 20
|
||||
marginBottom: 20,
|
||||
},
|
||||
button: {
|
||||
backgroundColor: '#4CAF50',
|
||||
padding: 15,
|
||||
borderRadius: 8
|
||||
},
|
||||
buttonText: {
|
||||
color: '#fff',
|
||||
fontWeight: 'bold'
|
||||
}
|
||||
});
|
||||
borderRadius
|
||||
|
||||
Reference in New Issue
Block a user