Skip to main content
import React, { useEffect, useState } from 'react';
import { Text, View } from 'react-native';
import { useStytch } from '@stytch/react-native';

export const CheckSensor = () => {
  const stytch = useStytch();
  const [sensorAvailable, setSensorAvailable] = useState(false);

  useEffect(() => {
    const checkSensor = async () => {
      if (stytch) {
        try {
          const available = await stytch.biometrics.getSensor({
            allowDeviceCredentials: true,
          });
          setSensorAvailable(available);
        } catch {
          setSensorAvailable(false);
        }
      }
    };

    checkSensor();
  }, [stytch]);

  return (
    <View>
      <Text>
        {sensorAvailable
          ? 'Biometric sensor is available'
          : 'Biometric sensor is not available'}
      </Text>
    </View>
  );
};
Call this method to check if biometric sensors are available on the device. This method can be used to determine whether or not to show biometric registration options.

Parameters

allowDeviceCredentials
boolean
Allows user to enter their device credentials (e.g. PIN code) as a fallback for failed biometric authentication. If this is set to false on registration, authentication will not be allowed to enable fallback to device credentials.

Response

available
boolean
Whether biometric sensors are available on the device.
request_id
string
Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
status_code
number
The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.