authorised PIN & fingerprint
This commit is contained in:
@@ -1,76 +1,17 @@
|
|||||||
import React from 'react';
|
import ReactNativeBiometrics from 'react-native-biometrics';
|
||||||
import { View, Text, TouchableOpacity, Alert, StyleSheet } from 'react-native';
|
|
||||||
import ReactNativeBiometrics, { BiometryTypes } from 'react-native-biometrics';
|
|
||||||
|
|
||||||
const FaceAuth = () => {
|
const rnBiometrics = new ReactNativeBiometrics();
|
||||||
|
|
||||||
const authenticate = async () => {
|
export const authenticateUser = async () => {
|
||||||
try {
|
const { available, biometryType } = await rnBiometrics.isSensorAvailable();
|
||||||
const rnBiometrics = new ReactNativeBiometrics({
|
|
||||||
allowDeviceCredentials: true, // Android PIN fallback
|
|
||||||
});
|
|
||||||
|
|
||||||
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');
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
const result = await rnBiometrics.simplePrompt({
|
||||||
biometryType === BiometryTypes.FaceID ||
|
promptMessage: 'Unlock using Face ID',
|
||||||
biometryType === BiometryTypes.Biometrics ||
|
|
||||||
biometryType === BiometryTypes.TouchID
|
|
||||||
) {
|
|
||||||
const authResult = await rnBiometrics.simplePrompt({
|
|
||||||
promptMessage: 'Authenticate to continue',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (authResult.success) {
|
return result.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>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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