Auth fails when using custom Livewire update endpoint
Package
filament/filament
Package Version
v3.1.35
Laravel Version
v10.39.0
Livewire Version
v3.3.5
PHP Version
PHP 8.3.0
Problem description
I'm currently installing Filament on an existing Livewire project, which has custom update endpoints.
All went well during the installation process, however, when trying to sign into the admin panel with the newly created user, it simply redirects me back to the login page without any error messages.
Removing the custom update endpoints in the LivewireServiceProvider, I am able to sign into the admin panel successfully.
Expected behavior
To be authenticated successfully and redirected to the admin panel.
Steps to reproduce
- Install clean Laravel 10 project
- Install Livewire 3
- Set custom update endpoint in the boot function of LivewireServiceProvider, example:
Livewire::setUpdateRoute(function ($handle) {
return Route::post('/custom/endpoint/update', $handle);
});
Livewire::setScriptRoute(function ($handle) {
return Route::get('/custom/livewire/livewire.js', $handle);
});
- Install Filament 3
- Run
php artisan filament:install --panelsand fill in default step - Create new Filament User
- Attempt to sign into the admin panel using the newly created user.
Reproduction repository
https://github.com/origjinali/livewire-filament-auth-bug
Relevant log output
Apologies if the reproduction repository is not complete, I don't currently have an editor available.
I do not use this feature of Livewire. So please perform your own investigations and see what is happening. The browser console is a good starting point to see errors.
NOTE: This is not a Filament Issue nor is it a bug. I have had quality time with the issue as well 😆 . It turns out the issue is that setting the updateRoute and scriptRoute manually was somehow overriding all middleware, including the most important one for Auth: web. Adding the web middleware as shown below sorted out the issue.
Livewire::setUpdateRoute(function ($handle) {
return Route::post('/custom/endpoint/update', $handle)->middleware('web');
});
Livewire::setScriptRoute(function ($handle) {
return Route::get('/custom/livewire/livewire.js', $handle)->middleware('web');
});
Thanks!