Import
use Native\Mobile\Facades\Biometrics;
Methods
prompt()
Initiate a biometric authentication prompt using Face ID (iOS) or fingerprint/face unlock (Android).
Returns a PendingBiometric instance for fluent API configuration.
$auth = Biometrics::prompt();
A pending biometric authentication instance
PendingBiometric Methods
The PendingBiometric class provides a fluent interface for configuring biometric authentication.
id()
Set a unique identifier for this biometric authentication to correlate with events.
Unique identifier for tracking this authentication attempt
Biometrics::prompt()
->id('login-attempt-123');
getId()
Get the biometric authentication’s unique identifier (generates one if not set).
$pending = Biometrics::prompt();
$id = $pending->getId();
The unique identifier (UUID if not manually set)
event()
Set a custom event class to dispatch when biometric authentication completes.
Fully qualified class name of the event to dispatch
use App\Events\UserAuthenticated;
Biometrics::prompt()
->event(UserAuthenticated::class);
remember()
Store this biometric authentication’s ID in the session for later retrieval.
Biometrics::prompt()
->id('auth-123')
->remember();
lastId()
Retrieve the last remembered biometric authentication ID from the session.
$lastId = \Native\Mobile\PendingBiometric::lastId();
The last remembered authentication ID, or null if none exists
prompt()
Explicitly start the biometric authentication prompt.
$success = Biometrics::prompt()
->id('auth-123')
->prompt();
True if the prompt was successfully initiated, false otherwise
Events
Biometric authentication results are delivered via events.
Completed
Dispatched when biometric authentication completes (success or failure).
use Native\Mobile\Events\Biometric\Completed;
use Illuminate\Support\Facades\Event;
Event::listen(Completed::class, function (Completed $event) {
if ($event->success) {
// User authenticated successfully
$id = $event->id;
} else {
// Authentication failed
}
});
Event Properties:
success (bool) - Whether authentication succeeded
id (string|null) - The tracking ID if one was set
Examples
Basic Authentication
use Native\Mobile\Facades\Biometrics;
// Simple authentication prompt
Biometrics::prompt();
Tracked Authentication with Event Handling
use Native\Mobile\Facades\Biometrics;
use Native\Mobile\Events\Biometric\Completed;
use Illuminate\Support\Facades\Event;
// In your controller or component
Biometrics::prompt()
->id('login-' . auth()->id())
->remember();
// In your event listener
Event::listen(Completed::class, function (Completed $event) {
$userId = str_replace('login-', '', $event->id);
if ($event->success) {
Log::info("User {$userId} authenticated successfully");
// Complete login process
} else {
Log::warning("User {$userId} failed biometric authentication");
}
});
Custom Event
use Native\Mobile\Facades\Biometrics;
use App\Events\BiometricLoginAttempt;
Biometrics::prompt()
->event(BiometricLoginAttempt::class)
->id('session-' . session()->getId());
Livewire Integration
use Livewire\Component;
use Native\Mobile\Facades\Biometrics;
use Native\Mobile\Events\Biometric\Completed;
use Livewire\Attributes\On;
class LoginForm extends Component
{
public function authenticateWithBiometrics()
{
Biometrics::prompt()
->id('livewire-auth')
->remember();
}
#[On('native:Native\\Mobile\\Events\\Biometric\\Completed')]
public function handleBiometricResult($data)
{
if ($data['success']) {
auth()->login($this->user);
return redirect()->route('dashboard');
}
$this->addError('auth', 'Biometric authentication failed');
}
}