jtargosz / filament-action-otp
Confirm dangerous Filament actions (delete, export, bulk actions) with a one-time code: ->requiresOtp()
Requires
- php: ^8.3
- filament/actions: ^4.17.1|^5.12.1
- filament/forms: ^4.17.1|^5.12.1
- filament/notifications: ^4.17.1|^5.12.1
- filament/support: ^4.17.1|^5.12.1
- illuminate/support: ^12.0|^13.0
- jtargosz/laravel-action-otp: ^2.2
Requires (Dev)
- filament/tables: ^4.17.1|^5.12.1
- laravel/pint: ^1.0
- orchestra/testbench: ^10.0|^11.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0|^12.0|^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Confirm dangerous Filament actions with a one-time code. Add ->requiresOtp() to a delete, export or bulk action. The user gets a code by mail (or SMS), types it into the modal, and only then the action runs.
DeleteAction::make()->requiresOtp()
Filament's built-in MFA protects the login. This plugin protects single actions after login: deleting records, exporting customer data, refunding an order.
Built on laravel-action-otp, which handles code generation, expiry, attempt lockout, send cooldown and the translated mail.
Requirements
- PHP 8.3, 8.4 or 8.5
- Laravel 12 or 13
- Filament 4 or 5
- A persistent cache driver (file, database, redis). The array driver loses codes between requests.
Install
composer require jtargosz/filament-action-otp
That's it. The code is sent with the default mail of laravel-action-otp. To change it, publish its config: php artisan vendor:publish --tag=action-otp-config.
Usage
Call requiresOtp() last in the chain:
use Filament\Actions\DeleteAction; use Filament\Actions\DeleteBulkAction; use Filament\Actions\ExportAction; public function table(Table $table): Table { return $table ->headerActions([ ExportAction::make()->exporter(CustomerExporter::class)->requiresOtp(), ]) ->recordActions([ DeleteAction::make()->requiresOtp(), ]) ->toolbarActions([ DeleteBulkAction::make()->requiresOtp(), ]); }
It works on any action with an action() closure:
Action::make('refund') ->schema([TextInput::make('reason')->required()]) ->action(fn (Order $record, array $data) => $record->refund($data['reason'])) ->requiresOtp();
What happens:
- Opening the modal sends a code to the logged-in user. Reopening it does not send another one while the code is valid.
- The modal shows the action's own form (if any) plus a code field with one-time-code autofill and a "Send a new code" link.
- A wrong code is a field error and counts as an attempt. An error in another field keeps the code.
- The correct code is consumed and the action runs once.
A record action gets a separate code per record, so a code sent for one row never deletes another.
Remember the confirmation
Skip the code for the same action for a while, for example when deleting several rows one by one:
DeleteAction::make()->requiresOtp(rememberFor: 300) // seconds
The confirmation is remembered per action and session, not per record. Without rememberFor every call needs a new code.
Call it last
requiresOtp() wraps the action's action(), schema() and mountUsing(). Calling one of these after it would remove the code check, so the plugin throws a LogicException when the action opens. Wizard actions are not supported.
Who gets the code
By default the current user: getEmailForVerification(), then getAuthIdentifier() as the identifier, and the user itself as the notifiable. Change it in a service provider:
use Jtargosz\FilamentActionOtp\FilamentActionOtp; FilamentActionOtp::identifyUsing(fn (User $user) => $user->phone); FilamentActionOtp::notifyUsing(fn (User $user) => Notification::route('vonage', $user->phone)); FilamentActionOtp::userUsing(fn () => Filament::auth()->user()); // default: auth()->user(), then the panel guard
For SMS, point the notification config of the core package at your SMS notification, see Notifications and SMS.
Settings
Code length, format, lifetime, attempts and cooldown come from config/action-otp.php of the core package. Throttling is per user identifier across all actions.
Testing
ActionOtp::fake() records the codes instead of sending them:
use Jtargosz\ActionOtp\Facades\ActionOtp; use Jtargosz\FilamentActionOtp\OtpConfirmation; public function test_deleting_a_customer_needs_the_code(): void { ActionOtp::fake('123456'); $customer = Customer::factory()->create(); Livewire::test(ListCustomers::class) ->callAction(TestAction::make('delete')->table($customer), ['otp_code' => '123456']); ActionOtp::assertSent(OtpConfirmation::class); $this->assertModelMissing($customer); }
For random codes use ActionOtp::fake() and ActionOtp::codeFor($email, FilamentActionOtp::purpose(ListCustomers::class, 'delete', $customer->getKey())).
Translations
en, pl, de, es, fr, it, nl and pt. Publish with php artisan vendor:publish --tag=filament-action-otp-lang.
Security
- Codes are bound to the browser session and to the action (and record), and compared in constant time.
- Wrong codes count toward the lockout of the core package (
max_attempts,throttle_seconds). - Only a marker waits in the cache. The action itself runs in the request that verifies the code.
Report vulnerabilities privately, see SECURITY.md.
License
MIT. See LICENSE.