Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Surajshetty's avatar

TWO FACTOR AUTHENTICATION(2FA) IN FILAMENT?

Need some guide for two factor auth in filament, is there any good plugin out there?

0 likes
5 replies
LaryAI's avatar
Level 58

Filament is a TALL stack admin panel for Laravel that doesn't come with built-in two-factor authentication (2FA) support. However, you can integrate 2FA into your Filament admin panel by using Laravel's built-in two-factor authentication services or by using a package like laravel/fortify which provides the backend controllers and routes necessary for 2FA.

Here's a general guide on how you can add 2FA to your Filament admin panel:

  1. Install Laravel Fortify (if you haven't already):
composer require laravel/fortify
  1. Publish Fortify's resources:
php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"
  1. Configure Fortify to use the views you want for 2FA by modifying the fortify.php config file.

  2. Implement the two-factor authentication routes in your routes/web.php file:

use Laravel\Fortify\Http\Controllers\TwoFactorAuthenticatedSessionController;

Route::group(['middleware' => ['web', 'auth']], function () {
    Route::post('/user/two-factor-authentication', [TwoFactorAuthenticatedSessionController::class, 'store'])
        ->name('two-factor.enable');

    Route::delete('/user/two-factor-authentication', [TwoFactorAuthenticatedSessionController::class, 'destroy'])
        ->name('two-factor.disable');

    // Other 2FA routes...
});
  1. Update your User model to use the TwoFactorAuthenticatable trait:
use Laravel\Fortify\TwoFactorAuthenticatable;

class User extends Authenticatable
{
    use TwoFactorAuthenticatable;
    // ...
}
  1. Create the necessary database columns for 2FA by creating a new migration:
php artisan make:migration add_two_factor_columns_to_users_table --table=users

Then, in the migration file:

public function up()
{
    Schema::table('users', function (Blueprint $table) {
        $table->text('two_factor_secret')->after('password')->nullable();
        $table->text('two_factor_recovery_codes')->after('two_factor_secret')->nullable();
    });
}

public function down()
{
    Schema::table('users', function (Blueprint $table) {
        $table->dropColumn('two_factor_secret', 'two_factor_recovery_codes');
    });
}

Run the migration:

php artisan migrate
  1. Integrate 2FA into your Filament admin panel by overriding the login and two-factor challenge views with your own. You can publish Filament's views and modify them to include the 2FA fields:
php artisan vendor:publish --tag=filament-views
  1. Handle the 2FA challenge after the user logs in. You may need to customize the login controller to redirect users to a 2FA challenge page if they have 2FA enabled.

  2. Test your implementation thoroughly to ensure that 2FA is working as expected.

Please note that this is a high-level guide and assumes familiarity with Laravel, Filament, and Fortify. You may need to adjust the steps based on your specific setup and requirements. Always refer to the official documentation of Laravel, Fortify, and Filament for the most accurate and up-to-date instructions.

Surajshetty's avatar

Is there any other good plugin that is already integrated with the filament

martinbean's avatar
Level 80

@Surajshetty Authentication is not something Filament should be concerned about. Authentication is something your application should be handling.

You can add 2FA to an application by using Laravel’s Jetstream starter kit, or Fortify for an existing application.

1 like

Please or to participate in this conversation.