Installation:
composer require webbingbrasil/filament-2fa
php artisan vendor:publish --tag="filament-2fa-migrations"
php artisan migrate
Ensure filament >= 2.10.40 is installed.
User Model Trait:
Add \Webbingbrasil\FilamentTwoFactor\TwoFactorAuthenticatable to your User model.
Configure Filament Auth:
Update config/filament.php:
"auth" => [
"pages" => [
"login" => \Webbingbrasil\FilamentTwoFactor\Http\Livewire\Auth\Login::class,
],
],
First Use Case:
Login Flow:
Profile Integration:
<livewire:filament-two-factor-form> to a custom profile page (e.g., Jetstream theme):
<livewire:filament-two-factor-form />
Customization:
resources/views/vendor/filament-2fa/).config/filament-2fa.php to adjust:
Middleware:
\Webbingbrasil\FilamentTwoFactor\Http\Middleware\EnsureTwoFactorEnabled to restrict routes:
Route::middleware([EnsureTwoFactorEnabled::class])->group(...);
Migration Conflicts:
users table already has two_factor_secret or two_factor_recovery_codes, manually merge migrations or drop columns first.php artisan vendor:publish --tag="filament-2fa-migrations" before migrate.Trait Collisions:
laravel-2fa). Remove conflicting traits/secrets.Backup Codes:
Caching Issues:
php artisan filament:cache:clear) after config changes or trait additions.QR Code Errors:
google/authenticator is installed (composer require google/authenticator).storage/logs/laravel.log for QR generation failures.Login Redirect Loops:
FILAMENT_AUTH_GUARD in .env matches the guard used in config/filament.php.Custom Recovery Flow:
Override the recovery logic in app/Providers/FilamentServiceProvider.php:
FilamentTwoFactor::recovery(function ($user, $code) {
// Custom validation logic
});
Event Listeners:
Listen for 2FA events (e.g., TwoFactorEnabled, TwoFactorDisabled) in EventServiceProvider:
protected $listen = [
\Webbingbrasil\FilamentTwoFactor\Events\TwoFactorEnabled::class => [
\App\Listeners\LogTwoFactorEnable::class,
],
];
Testing:
Use the TwoFactorAuthenticatable trait’s helper methods in tests:
$user->enableTwoFactorAuth(); // Manually enable 2FA
$user->disableTwoFactorAuth();
How can I help you explore Laravel packages today?