filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.34k stars 2.86k forks source link

DownloadImportFailureCsv gives error with more than one guard #12742

Open leonardyrj opened 5 months ago

leonardyrj commented 5 months ago

Package

filament/actions

Package Version

v3.2.76

Laravel Version

v11.7.0

Livewire Version

v3.4.12

PHP Version

PHP 8.3.0

Problem description

I'm using two panels with different guards.

When I'm importing and it fails, it always tries to find the user in the default guard. There should be an option to choose which guard the user should look for.

It tries to login in to the default guard

Captura de Tela 2024-05-11 às 13 33 21

I think in this part of the code you should choose which guard to use

Expected behavior

When trying to download the file, it should not try to authenticate to a different guard than the one logged in

Steps to reproduce

Upload this file, in the resource car I put the date in an invalid format. And then try to download the failed file.

car-importer-example (1).csv

Reproduction repository

https://github.com/leonardyrj/filament-issue

Relevant log output

No response

Donate 💰 to fund this issue

Fund with Polar

danharrin commented 4 months ago

I would accept a PR to allow customisation of the guard

leonardyrj commented 4 months ago

Eu aceitaria um PR para permitir a personalização da guarda

The problem is in this action middleware, you would have to somehow add additional middleware.

Correct me if I'm wrong. The Action module is to be used independently, so I can't get the guard from the panel.

Would I have to manually add it to the action module?

In my case it would be auth:admin

ActionServiceProvider.php

Captura de Tela 2024-05-29 às 11 41 40

Needs to be customizable

How is the route

Captura de Tela 2024-05-29 às 11 45 47
spcbfr commented 3 months ago

If anyone comes across this issue, here is a hack to temporarily solve the issue:

Add this to your AppServiceProvider.php and replace admin with the name of your custom auth guard

app(Router::class)->middlewareGroup('filament.actions', ['web', 'auth:admin']);
ronssij commented 3 months ago

@spcbfr Thanks!! This saved me, I have been looking for a way to override this.

DiogoLindoso commented 2 months ago

Perhaps the routes to import csv should be within the panel routes, from what I saw the import routes do not take into account the context of which panel was requested

danharrin commented 2 months ago

Imports and exports can be used outside of panels.

leonardyrj commented 2 months ago

So it gets a little complex, there would have to be some way to change the middleware in the project itself.

leonardyrj commented 2 months ago

In my project I solved it this way

Route::get('/filament/imports/{import}/failed-rows/download', DownloadImportFailureCsv::class) ->name('filament.imports.failed-rows.download') ->middleware('auth:consignante');