Downloading exported resources problem (problem with the auth guards)

I have a filament resource and I want to export then download them as a csv file. I set up everything as the filament documentation said so I can export the resources with a bulk action, then I get the notification where I can click the download csv button. After I did these I got the error Route [login] not defined. So I added this code to the web.php:
Route::get('/laravel/login',
fn() => redirect(route('filament.admin.auth.login'))
)->name('login');
Route::get('/laravel/login',
fn() => redirect(route('filament.admin.auth.login'))
)->name('login');
With this modification it doesn't gives the error but the system opens a new window and redirects me to my filament dashboard instead of the csv gets downloaded. Anyone have something in mind what can I do with this?
Solution:
I managed to discover the problem and solved it! The problem is that my filament app uses admin auth guard but the page where the download happens uses the user auth guard... That was why the system wanted to log me in. ...
Jump to solution
3 Replies
lazydog
lazydog6mo ago
Please find your Filament Service Provider, and check if there is ->login() else add it.
csabit1000
csabit1000OP6mo ago
Yes I have ->login() in on my panel in the panel provider. Actualy I have a package which creates a panel in the PackagePanelProvider and there are set the main panel options that are important for me (resources, navigationGroups etc.) I use that package in my project and the ProjectPanelProvider extends the PackagePanelProvider. So theoretically if I override the panel function of the PackagePanelProvider and call the parent panel function I could use the predefined panel:
public function panel(Panel $panel): Panel
{
// get the original panel to extend it
$customPanel = parent::panel($panel);

// the panel from the package that is customizable
return $customPanel
->databaseNotifications();
}
public function panel(Panel $panel): Panel
{
// get the original panel to extend it
$customPanel = parent::panel($panel);

// the panel from the package that is customizable
return $customPanel
->databaseNotifications();
}
Note: The panel of the PackagePanelProvider uses the ->login() option. (Also I have tried to apply the ->login() in the ProjectPanelProvider too, but no luck) One more important thing. My export user isn't the default user model. I changed it to my admin model. AppServiceProvider.php
/**
* Register any application services.
*/
public function register(): void
{
$this->app->bind(Authenticatable::class, Admin::class);
}
/**
* Register any application services.
*/
public function register(): void
{
$this->app->bind(Authenticatable::class, Admin::class);
}
Exports migration:
$table->foreignId('user_id')->constrained('admins')->cascadeOnDelete();
$table->foreignId('user_id')->constrained('admins')->cascadeOnDelete();
One more thing that I discovered yesterday that on the download .csv click I don't have any guards. I have called dd(auth()) from the Authenticate middleware and the guards array is completely empty.
Solution
csabit1000
csabit10006mo ago
I managed to discover the problem and solved it! The problem is that my filament app uses admin auth guard but the page where the download happens uses the user auth guard... That was why the system wanted to log me in. The work around (actually a hack) that I used is to redefine the download route in the web.php and use the appropriate guard. web.php
use Filament\Actions\Exports\Http\Controllers\DownloadExport;

Route::get('/filament/exports/{export}/download', DownloadExport::class)
->name('filament.exports.download')
->middleware(['web', 'auth:admin']);
use Filament\Actions\Exports\Http\Controllers\DownloadExport;

Route::get('/filament/exports/{export}/download', DownloadExport::class)
->name('filament.exports.download')
->middleware(['web', 'auth:admin']);
Want results from more Discord servers?
Add your server