filament icon indicating copy to clipboard operation
filament copied to clipboard

Auth fails when using custom Livewire update endpoint

Open origjinali opened this issue 1 year ago • 1 comments

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

  1. Install clean Laravel 10 project
  2. Install Livewire 3
  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);
});
  1. Install Filament 3
  2. Run php artisan filament:install --panels and fill in default step
  3. Create new Filament User
  4. 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.

origjinali avatar Jan 07 '24 22:01 origjinali

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.

danharrin avatar Jan 08 '24 12:01 danharrin

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');
});

coolsam726 avatar Feb 27 '24 23:02 coolsam726

Thanks!

danharrin avatar Feb 28 '24 00:02 danharrin