Lesson 5 of 10
Biometrics - Face ID & Fingerprint
Biometric authentication lets users unlock sensitive parts of the app (payments, viewing passwords) without re-entering their PIN. expo-local-authentication wraps iOS Face ID / Touch ID and Android Biometric API.
Biometric Auth Pattern
import * as LocalAuthentication from 'expo-local-authentication';
import * as SecureStore from 'expo-secure-store';
export async function isBiometricAvailable(): Promise<boolean> {
const compatible = await LocalAuthentication.hasHardwareAsync();
if (!compatible) return false;
const enrolled = await LocalAuthentication.isEnrolledAsync();
return enrolled;
}
export async function authenticateWithBiometrics(prompt: string): Promise<boolean> {
const available = await isBiometricAvailable();
if (!available) return false; // fall back to PIN/password
const result = await LocalAuthentication.authenticateAsync({
promptMessage: prompt, // "Authenticate to view your saved cards"
fallbackLabel: 'Use passcode',
cancelLabel: 'Cancel',
disableDeviceFallback: false, // allow PIN fallback on iOS
});
return result.success;
}
// ---- Hook ----
export function useBiometricAuth() {
const [isAvailable, setIsAvailable] = useState(false);
const [biometricType, setBiometricType] = useState<string>('');
useEffect(() => {
(async () => {
const available = await isBiometricAvailable();
setIsAvailable(available);
if (available) {
const types = await LocalAuthentication.supportedAuthenticationTypesAsync();
// 1 = fingerprint, 2 = facial, 3 = iris
setBiometricType(types.includes(2) ? 'Face ID' : types.includes(1) ? 'Touch ID' : 'Biometric');
}
})();
}, []);
async function authenticate(prompt: string) {
return authenticateWithBiometrics(prompt);
}
return { isAvailable, biometricType, authenticate };
}
// ---- Usage: protect payment screen ----
function PaymentScreen() {
const [unlocked, setUnlocked] = useState(false);
const { isAvailable, biometricType, authenticate } = useBiometricAuth();
useEffect(() => {
if (isAvailable) {
authenticate(`Authenticate with ${biometricType} to access payment`).then(setUnlocked);
} else {
setUnlocked(true); // no biometrics - allow access
}
}, [isAvailable]);
if (!unlocked) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text style={{ fontSize: 48 }}>{biometricType === 'Face ID' ? 'π' : 'π'}</Text>
<Text style={{ color: '#f1f5f9', marginTop: 16 }}>Authentication required</Text>
</View>
);
}
return <View><Text style={{ color: '#f1f5f9' }}>Your payment details here</Text></View>;
}Tip
Tip
Practice Biometrics Face ID Fingerprint in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Secure local biometric authentication via expo-local-authentication
Practice Task
Note
Practice Task - (1) Write a working example of Biometrics Face ID Fingerprint from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Biometrics Face ID Fingerprint is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.
Finished this lesson?