Checks if biometric sensors are available on the device. This method can be used to determine whether or not to show biometric registration options.
Get sensor
Method parameters
allowDeviceCredentials string
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.
import { useStytch } from '@stytch/react-native';
import React, { useCallback, useEffect, useState } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
export const Register = () => {
const stytch = useStytch();
const [isSensorAvailable, setIsSensorAvailable] = useState(false);
useEffect(() => {
const checkSensorAvailability = async () => {
if (stytch) {
try {
await stytch.biometrics.getSensor();
setIsSensorAvailable(true);
} catch {
setIsSensorAvailable(false);
}
} else {
setIsSensorAvailable(false);
}
};
checkSensorAvailability();
}, [stytch]);
const registerBiometrics = useCallback(() => {
stytch.biometrics.register({
prompt: 'Register with Biometrics',
});
}, [stytch]);
return isSensorAvailable ? (
<View>
<TouchableOpacity onPress={registerBiometrics}>
<Text>Register with Biometrics</Text>
</TouchableOpacity>
</View>
) : null;
};