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

HectorOrdonez's avatar

Fresh Laravel authentication not persisting

I have spent a lot of hours in this problem.

Eventually I decided to make a fresh laravel app and test the basics.

All I did was:

  • create laravel app
  • add breeze
  • breeze:install with livewire
  • run migrations
  • artisan serve
  • registered a user
  • logged in with user
  • refresh, still works

At this point, I modified the web.php routes like this:

[...]
Route::get('test', function() {
    if(Auth::check())
    {
        dump('user logged in');
    } else {
        dump('user not logged in');
    }

    dump('attempting manual login');
    $user = \App\Models\User::query()->first();

    Auth::attempt(['email'=> '[email protected]', 'password' => '123123123']);

    dump(Auth::user());
    request()->session()->regenerate();
    dump(Auth::user());
});

The user credentials are valid, and confirmed.

When hitting test, user is not logged in, then it is logged in and shown in both dumps, before and after session regenerating.

However if I hit it again, I would expect the prompt "user logged in", but it does not happen. User is not logged in.

Am I using Auth incorrectly?

0 likes
3 replies
martinbean's avatar

@hectorordonez Why are you trying to manually log users in, in the first place? Starter kits like Breeze give you authentication out of the box. It’s literally what they’re for.

HectorOrdonez's avatar

@martinbean Hello Martin. I am writing a laravel project where I want to use ddd and hexagonal architecture. In order to do this I am detaching laravel from eloquent and its authentication system. I was following a video in laracasts where Jeffrey explains how to use authentication without passwords - using login links to email.

I was almost done, but the session problem appeared. And here we are.

kiko's avatar

Im exactly here and cant find the reason... In my case was by having defined a SESSION_DOMAIN into .env

Please or to participate in this conversation.