authorised PIN & fingerprint
This commit is contained in:
@@ -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 (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.title}>Face Authentication</Text>
|
||||
|
||||
<TouchableOpacity style={styles.button} onPress={authenticate}>
|
||||
<Text style={styles.buttonText}>Authenticate</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
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',
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user