Local authentication for react native, supports iOS only.
npm install react-native-local-authenticationLocal authentication for react native, supports iOS only. See iOS Local Authentication Document
* react-native-local-authentication
* Install
* Usage
* setLocalizedFallbackTitle(title)
* setLocalizedCancelTitle(title)
* canEvaluate(policy)
* Parameters
* Response
* evaluate(policy, localizedReason)
* parameters
* Response
* invalidate()
* LAError
* Example
``sh`
npm i --save react-native-local-authentication
react-native link react-native-local-authentication
Set fallback button title.
Set cancel button title.
Determines if a particular policy can be evaluated.
#### Parameters
* policy
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
#### parameters
* policy
Policy for which the preflight check should be run.
* localizedReason
Policy for which the preflight check should be run.
#### Response
Successful
return true
Failed
* code: see LAError
* message: error message
Invalidates the context.
error code
* LAErrorAuthenticationFailed
* LAErrorUserCancel
* LAErrorUserFallback
* LAErrorSystemCancel
* LAErrorPasscodeNotSet
* LAErrorTouchIDNotAvailable DEPRECATEDDEPRECATED
* LAErrorTouchIDNotEnrolled DEPRECATED
* LAErrorTouchIDLockout
* LAErrorAppCancel
* LAErrorInvalidContext
* LAErrorNotInteractive
* LAErrorBiometryNotAvailable
* LAErrorBiometryNotEnrolled
* LAErrorBiometryLockout
`js
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);
}
}
};
``