Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

youcefkacem's avatar

login issue with livewire and session

i have this error in the login functionality when i try to log in the Auth::check() return true in the same livewire class

this is the code

public function login()
{
    $validated = $this->validate([
        'email' => 'required|email',
        'password' => 'required|min:8'
    ]);
    if (auth()->attempt($validated)) {
        session()->regenerate();
    }
    $this->reset();
    dd(Auth::check());


}

but when i try to dd(Auth::check()) in the web.php file where all the routs i get false thsi is the code

Route::get('/test', function(){ dd(Auth::check()); })->name('test');

how to fix that

0 likes
4 replies
experimentor's avatar

In the login method, auth()->attempt($validated) is setting Auth::check() to true.

If your test route has "auth" middleware, and you are logged in, it should return true. Is the test route public? If yes, Auth::check() may return false.

youcefkacem's avatar

thanks , i fix that by adding remember : true in the attempt() method

youcefkacem's avatar

also you can change the SESSION_DRIVER in .env file from database to file this used to store the session from database to file this fix the issue with login and show page expired when ever your livewire execute a method in the livewire component

Snapey's avatar

when you dd, session data is not saved, so make sure you do not dd after auth attempt

1 like

Please or to participate in this conversation.