react-native-local-authentication
v0.1.1
Published
Local authentication for react native, supports iOS only.
Downloads
369
Maintainers
Readme
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
- 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
evaluate(policy, localizedReason)
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
invalidate()
Invalidates the context.
LAError
error code
- LAErrorAuthenticationFailed
- LAErrorUserCancel
- LAErrorUserFallback
- LAErrorSystemCancel
- LAErrorPasscodeNotSet
- LAErrorTouchIDNotAvailable
DEPRECATED
- LAErrorTouchIDNotEnrolled
DEPRECATED
- LAErrorTouchIDLockout
DEPRECATED
- LAErrorAppCancel
- LAErrorInvalidContext
- LAErrorNotInteractive
- LAErrorBiometryNotAvailable
- LAErrorBiometryNotEnrolled
- LAErrorBiometryLockout
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);
}
}
};