Skip to content

Instantly share code, notes, and snippets.

@felisio
Created July 28, 2021 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felisio/075ebcbabd05e46fee3818c73f6331f1 to your computer and use it in GitHub Desktop.
Save felisio/075ebcbabd05e46fee3818c73f6331f1 to your computer and use it in GitHub Desktop.
React Native Fingerprint scanner code example
import React from 'react';
import {
Button,
Dimensions,
SafeAreaView,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
import FingerprintScanner from 'react-native-fingerprint-scanner';
async function verifyIfSensorIsAvailable() {
const biometryType = await FingerprintScanner.isSensorAvailable();
if (
biometryType === 'Touch ID' ||
biometryType === 'Face ID' ||
biometryType === 'Biometrics'
) {
return true;
}
return false;
}
async function getCredentials() {
try {
await FingerprintScanner.authenticate({
description: 'Biometric Scan Test',
});
console.log('BIOMETRIC SUCESS 😎');
} catch (error) {
console.error('Biometric Erro authenticate:', error);
}
}
function loginByBiometric() {
if (verifyIfSensorIsAvailable()) {
getCredentials();
}
}
function App() {
return (
<SafeAreaView>
<ScrollView contentInsetAdjustmentBehavior="automatic">
<View style={styles.viewContainer}>
<Text>React Native App Test</Text>
<Button onPress={loginByBiometric} title="Test Biometric Login" />
</View>
</ScrollView>
</SafeAreaView>
);
}
const WINDOW_WIDTH = Dimensions.get('window').width;
const WINDOW_HEIGHT = Dimensions.get('window').height;
const styles = StyleSheet.create({
viewContainer: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
padding: 10,
width: WINDOW_WIDTH,
height: WINDOW_HEIGHT - 30,
},
});
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment