React Native Biometric Authentication Change Detector
This package provides a React Native module to determine if a user's biometric authentication settings (e.g., fingerprint, face ID) have changed on their device since the last check. This functionality is crucial for security-sensitive applications that need to re-authenticate users if their biometric credentials might have been altered, removed, or reset. As of version 0.1.1, it offers two primary functions: `checkBiometricAuthChanged` to detect if a change has occurred and `isBiometricAuthAvailable` to ascertain if biometric authentication is even configured on the device. Given its very low version number, it is in its early development stages, suggesting a potentially irregular release cadence as new features or bug fixes are implemented. It aims to provide a cross-platform (iOS and Android) solution specifically for biometric security change detection, differentiating itself by focusing on this aspect rather than general biometric authentication processes like prompting for a scan.
Common errors
-
The package 'react-native-check-biometric-auth-changed' doesn't seem to be linked. Make sure: - You have run 'pod install' - You rebuilt the app after installing the package - You are not using Expo Go
cause The native module was not correctly linked into your iOS or Android project, or you are running in an unsupported environment like Expo Go.fixFor iOS, navigate to your `ios/` directory and run `pod install`. Rebuild your entire React Native application after installation (e.g., `npx react-native run-ios` or `npx react-native run-android`). If using Expo, ensure you are in a bare workflow or using a custom development client, not Expo Go. -
TypeError: (0, _reactNativeCheckBiometricAuthChanged.multiply) is not a function
cause You are attempting to call the boilerplate `multiply` function from the initial `create-react-native-library` template, which is not the actual API exposed by this package.fixReplace calls to `multiply` with the correct functions: `checkBiometricAuthChanged()` or `isBiometricAuthAvailable()`. Refer to the package's source code or its intended documentation for accurate API usage.
Warnings
- breaking As this package is in a very early version (0.1.1), breaking changes may occur in minor or even patch releases. Developers should pin exact versions and carefully review release notes before updating.
- gotcha The `multiply` function shown in the README is boilerplate and does not represent the package's actual functionality. The true exports are `checkBiometricAuthChanged` and `isBiometricAuthAvailable`.
- gotcha Like many React Native native modules, this package requires proper linking to the native projects (iOS and Android). Failure to do so will result in runtime errors stating the package is not linked.
- gotcha This package is specifically designed to detect *changes* in biometric authentication settings, not to perform authentication prompts itself. You will need another library for the actual biometric authentication UI.
Install
-
npm install react-native-check-biometric-auth-changed -
yarn add react-native-check-biometric-auth-changed -
pnpm add react-native-check-biometric-auth-changed
Imports
- checkBiometricAuthChanged
import checkBiometricAuthChanged from 'react-native-check-biometric-auth-changed'; // Not a default export
import { checkBiometricAuthChanged } from 'react-native-check-biometric-auth-changed'; - isBiometricAuthAvailable
const { isBiometricAuthAvailable } = require('react-native-check-biometric-auth-changed'); // CommonJS is not the primary pattern for modern RN modules.import { isBiometricAuthAvailable } from 'react-native-check-biometric-auth-changed';
Quickstart
import { checkBiometricAuthChanged, isBiometricAuthAvailable } from 'react-native-check-biometric-auth-changed';
import { useEffect, useState } from 'react';
import { Alert } from 'react-native';
const BiometricStatusChecker = () => {
const [biometricsChanged, setBiometricsChanged] = useState(false);
const [biometricsSupported, setBiometricsSupported] = useState(false);
useEffect(() => {
const checkBiometrics = async () => {
try {
const available = await isBiometricAuthAvailable();
setBiometricsSupported(available);
if (available) {
const changed = await checkBiometricAuthChanged();
setBiometricsChanged(changed);
if (changed) {
Alert.alert(
'Security Alert',
'Your biometric authentication settings have changed. Please re-authenticate or re-enroll for security purposes.'
);
} else {
console.log('Biometric settings are unchanged.');
}
} else {
console.log('Biometric authentication is not available or enrolled.');
}
} catch (error) {
console.error('Failed to check biometric status:', error);
Alert.alert('Error', 'Could not check biometric status: ' + error.message);
}
};
checkBiometrics();
}, []);
return (
// Your component rendering logic based on biometricsChanged and biometricsSupported
// For example, display a message or trigger a re-authentication flow
null
);
};
export default BiometricStatusChecker;