I'm currently trying to implement filament v3 into my current laravel v10 project also using livewire v3.
After installing filament v3 as described in their installation guide I am able to see the filament login screen where I can log in under certain conditions:
I have already searched everywhere I could and found just a few people with the same or a similar problem:
SESSION_DRIVER
to SESSION_DRIVER=file
instead of SESSION_DRIVER=database
everything works as expected but I can't find the solution WHY?!SESSION_DRIVER=database
).I now found a solution to bypass the problem:
<?php
namespace App\Providers\Filament;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->colors([
'primary' => Color::Rose,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
// StartSession::class, -> just commented out this line
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
]);
}
}
Now I'm not completely sure if this is okay to do.
What I've encountered before: Every time I go to the filament dashboard or am redirected to the filament login screen a new session entry get's generated in the database where the old one get's abandoned (not deleted as normally when logging out).
After commenting out StartSession::class
in my AdminPanelProvider.php
file this is no longer the case.
Now every time I log in (or log out) the session get's updated (or deleted and a new one get's created).
Is this safe to implement like this?
Also why is it working just fine if SESSION_DRIVER=file
?
For anyone stumbling on to this question... I finally found a solution for my project.
Although it's very unlikely anyone else is experiencing the exact same issue I will still post my findings:)
For me the reason for the bug could be found in the app/Http/Kernel.php
file.
The following changes fixed it for me:
A bit on the background:
The project was started with Laravel v7 and grew since then... Maybe those days the Kernel.php
file looked different to the todays version or I just modified it some time ago.