Last active
September 19, 2018 04:35
-
-
Save adhithiravi/ff46dd6d749ada7ae5d42e0b07fb335d to your computer and use it in GitHub Desktop.
Example showing authentication using touch id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import React, { Component } from 'react'; | |
import { | |
AlertIOS, | |
StyleSheet, | |
Text, | |
TouchableHighlight, | |
View, | |
} from 'react-native'; | |
import TouchID from "react-native-touch-id"; | |
export default class FingerPrint extends Component<{}> { | |
constructor() { | |
super() | |
this.state = { | |
biometryType: null | |
}; | |
} | |
componentDidMount() { | |
TouchID.isSupported() | |
.then(biometryType => { | |
this.setState({ biometryType }); | |
}) | |
} | |
render() { | |
return ( | |
<View style={styles.container}> | |
<TouchableHighlight | |
style={styles.btn} | |
onPress={this.clickHandler} | |
underlayColor="#0380BE" | |
activeOpacity={1} | |
> | |
<Text style={{ | |
color: '#fff', | |
fontWeight: '600' | |
}}> | |
{`Authenticate with ${this.state.biometryType}`} | |
</Text> | |
</TouchableHighlight> | |
</View> | |
); | |
} | |
clickHandler() { | |
TouchID.isSupported() | |
.then(authenticate) | |
.catch(error => { | |
AlertIOS.alert('TouchID not supported'); | |
}); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
backgroundColor: '#F5FCFF' | |
}, | |
btn: { | |
borderRadius: 3, | |
marginTop: 200, | |
paddingTop: 15, | |
paddingBottom: 15, | |
paddingLeft: 15, | |
paddingRight: 15, | |
backgroundColor: '#0391D7' | |
} | |
}); | |
function authenticate() { | |
return TouchID.authenticate() | |
.then(success => { | |
AlertIOS.alert('Authenticated Successfully'); | |
}) | |
.catch(error => { | |
console.log(error) | |
AlertIOS.alert(error.message); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment