@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.
Feb 26, 2024
3
Level 3
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?
Please or to participate in this conversation.