Started implementation of biometric (Face ID) authentication

This commit is contained in:
mansi-dev
2026-01-20 00:07:31 +05:30
parent 6b328f1733
commit d8a10a6777

72
src/screen/FaceAuth.tsx Normal file
View File

@@ -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 (
<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'
}
});