rn-local-authentication
Version:
The library helps you to authenticate users biometrically
73 lines • 1.96 kB
JavaScript
import { Platform } from 'react-native';
import LocalAuthenticationNativeModule from './nativeModule';
import { BiometryTypeIOSEnum, } from './types';
const { isSupportedAsync, isAvailableAsync, getBiometryStatusAsync, biometryType, authenticateAsync: nativeAuthenticateAsync, isReuseAvailable: isReuseAvailableFlag } = LocalAuthenticationNativeModule;
/**
* Get device supported biometry type
*
* @returns BiometryTypeIOS | null
*/
function getBiometryType() {
if (Platform.OS === 'android') {
return null;
}
switch (biometryType) {
case BiometryTypeIOSEnum.FaceID:
return 'FaceID';
case BiometryTypeIOSEnum.TouchID:
return 'TouchID';
default:
return 'None';
}
}
/**
* Authenticate user with their biometrics
*
* @param options AuthenticateOptionsIOS
* @return Promise<AuthenticateResponse>
*/
async function authenticateAsync(options) {
if (Platform.OS === 'android') {
if (!options.cancelTitle && !options.fallbackToPinCodeAction) {
options.cancelTitle = 'Cancel';
}
else if (options.cancelTitle && options.fallbackToPinCodeAction) {
options.cancelTitle = undefined;
}
}
const response = await nativeAuthenticateAsync(options);
if (response.warning) {
console.warn(response.warning);
}
return response;
}
/**
* Release memory (for android)
*/
function release() {
if (Platform.OS === 'android') {
return LocalAuthenticationNativeModule.release();
}
return;
}
/**
* Get reuse availability
*
* @returns boolean
*/
function isReuseAvailable() {
if (Platform.OS === 'android') {
return false;
}
return isReuseAvailableFlag;
}
export default {
isSupportedAsync,
isAvailableAsync,
getBiometryStatusAsync,
getBiometryType,
authenticateAsync,
release,
isReuseAvailable,
};
//# sourceMappingURL=index.js.map