React Native Biometric Authentication Change Detector

0.1.1 · active · verified Wed Apr 22

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to check if biometric authentication is available on the device and if the user's biometric settings have changed, alerting the user to re-authenticate if necessary for security reasons.

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;

view raw JSON →