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

bishtyogeshsingh's avatar

Issue with Laravel 11 Auth: Login Works, But Auth Is Null After Redirecting to Dashboard

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:

  1. Login Method in Controller Here's the code for my login method:
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.

  1. Index Method in Dashboard Controller Here is the code for the index() method in my dashboard controller:
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.

  1. Configuration Settings Below are the settings from my .env and auth.php configuration files:

.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!

0 likes
4 replies
Snapey's avatar

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?

bishtyogeshsingh's avatar

@Snapey I'm using Laravel's default authentication functions, so is there any additional implementation needed to ensure Laravel Auth works as expected?

Shivamyadav's avatar

If you're using custom column names like mprpUsers_email and mprpUsers_password, Laravel might fail to authenticate the user properly after the initial request.

protected $username = 'mprpUsers_email';

Just for testing purpose can you add the middleware to the dashboard that can be only accessible by auth user with the help of auth middleware which is provided by default in Laravel.

Please or to participate in this conversation.