Redirect is a new request cycle. If sessions are not working, or, if the data recorded in session does not align with a user record then you will get no user.
Does your customised Auth model have non standard primary key?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am facing an issue where the Laravel 11 authentication works perfectly on the login page but fails after redirecting to the dashboard. Here's how my current code looks and the steps I took for troubleshooting:
public function login(Request $request)
{
$credentials = [
'mprpUsers_email' => $request->input('email'),
'mprpUsers_password' => $request->input('password'),
];
$request->validate([
"email" => "required|email",
"password" => "required",
"profile" => "required|numeric",
]);
if (Auth::attempt($credentials)) {
dd(Auth::user()); // Debug line showing user data after login
return redirect()->intended('dashboard/author');
} else {
return Helper::setError('Invalid login credentials.');
}
}
When I run dd(Auth::user()) within this method, it displays all the user data as expected.
public function index()
{
dd(Auth::user()); // Debug line showing user data on the dashboard
}
When I use dd(Auth::user()) here, it returns null, even though the login method shows user data before redirection.
.env file:
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
I've also tried changing SESSION_DRIVER to file, but the issue persists.
auth.php file:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => env('AUTH_MODEL', App\Models\User::class),
],
],
I would greatly appreciate any insights or suggestions for resolving this issue. Has anyone faced a similar problem with Laravel 11 authentication not persisting after a redirect? Any help would be highly valued!
Please or to participate in this conversation.