Biometrics


#Overview

The Biometrics API allows you to authenticate users using their device's biometric sensors like Face ID, Touch ID, or fingerprint scanners.

Import
Copied!
use Native\Mobile\Facades\Biometrics;
Copied!
import { biometric, on, off, Events } from '#nativephp';

#Methods

#prompt()

Prompts the user for biometric authentication.

Biometric Prompt
Copied!
use Native\Mobile\Facades\Biometrics;
 
Biometrics::prompt();

Copied!
// Basic usage
await biometric.prompt();
 
// With an identifier for tracking
await biometric.prompt()
.id('secure-action-auth');

#Events

#Completed

Fired when biometric authentication completes (success or failure).

Completed Event
Copied!
use Native\Mobile\Attributes\OnNative;
use Native\Mobile\Events\Biometric\Completed;
 
#[OnNative(Completed::class)]
public function handle(bool $success)
{
if ($success) {
// User authenticated successfully
$this->unlockSecureFeature();
} else {
// Authentication failed
$this->showErrorMessage();
}
}

Copied!
import { biometric, on, off, Events } from '#nativephp';
import { ref, onMounted, onUnmounted } from 'vue';
 
const isAuthenticated = ref(false);
 
const handleBiometricComplete = (payload) => {
if (payload.success) {
isAuthenticated.value = true;
unlockSecureFeature();
} else {
showErrorMessage();
}
};
 
const authenticate = async () => {
await biometric.prompt();
};
 
onMounted(() => {
on(Events.Biometric.Completed, handleBiometricComplete);
});
 
onUnmounted(() => {
off(Events.Biometric.Completed, handleBiometricComplete);
});

Copied!
import { biometric, on, off, Events } from '#nativephp';
import { useState, useEffect } from 'react';
 
const [isAuthenticated, setIsAuthenticated] = useState(false);
 
const handleBiometricComplete = (payload) => {
if (payload.success) {
setIsAuthenticated(true);
unlockSecureFeature();
} else {
showErrorMessage();
}
};
 
const authenticate = async () => {
await biometric.prompt();
};
 
useEffect(() => {
on(Events.Biometric.Completed, handleBiometricComplete);
 
return () => {
off(Events.Biometric.Completed, handleBiometricComplete);
};
}, []);

#Platform Support

  • iOS: Face ID, Touch ID
  • Android: Fingerprint, Face unlock, other biometric methods
  • Fallback: System authentication (PIN, password, pattern)

#Security Notes

  • Biometric authentication provides convenience, not absolute security
  • Always combine with other authentication factors for sensitive operations
  • Consider implementing session timeouts for unlocked states
  • Users can potentially bypass biometrics if their device is compromised