react-native-local-authentication
Local authentication for react native, supports iOS only. See iOS Local Authentication Document
Install
npm i --save react-native-local-authentication
react-native link react-native-local-authentication
Usage
setLocalizedFallbackTitle(title)
Set fallback button title.
setLocalizedCancelTitle(title)
Set cancel button title.
canEvaluate(policy)
Determines if a particular policy can be evaluated.
Parameters
The policy to evaluate.
see LAPolicy
Response
Successful
see LABiometryType
- none: No biometry type is supported.
- touchID: The device supports Touch ID.
- faceID: The device supports Face ID.
Failed
- code: see LAError
- message: error message
evaluate(policy, localizedReason)
parameters
Policy for which the preflight check should be run.
Policy for which the preflight check should be run.
Response
Successful
return true
Failed
- code: see LAError
- message: error message
invalidate()
Invalidates the context.
LAError
error code
Example
import RNLocalAuthentication, { LAError, LABiometryType } from 'react-native-local-authentication';
async _evaluate() {
try {
const biometryType = await RNLocalAuthentication.canEvaluate();
if (biometryType && (biometryType === LABiometryType.touchID || LABiometryType.faceID)) {
const result = await RNLocalAuthentication.evaluate(1, biometryType === LABiometryType.touchID ? 'Evaluate Touch ID' : 'Evaluate Face ID');
console.log('evaluate', result ? 'evaluate successful' : 'evaluate failed');
Alert.alert('evaluate', result ? 'successful' : 'failed');
} else {
Alert.alert('Can not evaluate', biometryType);
}
} catch (e) {
console.log('evaluate', e.code, e.message, e);
if (parseInt(e.code) === LAError.LAErrorTouchIDNotAvailable) {
Alert.alert('Error', 'device does not support touch ID or face ID');
} else {
Alert.alert('Error', e.message);
}
}
};