Lavarel Auth session lost after request

180 Views Asked by At

We try to authenticate a user manually via the builtin Auth functionality.

We don't retain a database as that's not needed for our purpose.

We followed this part of the docs: https://laravel.com/docs/9.x/authentication#authenticate-a-user-instance

We make a user on a certain request, we checked the Auth::check() method and I get a true, so it's working:

$user = User::make([
        'name' => $userGoogle->name,
        'email' => $userGoogle->email,
        'token' => $userGoogle->token,
        'refresh_token' => $userGoogle->refreshToken,
        'employeeId' => $employeeId,
    ]);

    Auth::login($user);
    //request()->session()->invalidate(); //Needed?
    //request()->session()->regenerateToken(); //Needed?

    dd(Auth::check());

But, when loading another test page:

Route::get('test', function() {
    dd(Auth::check());
});

This always returns false. I also tried with regenerating the session token as I suspect something is going wrong there.

But no avail. It just doesn't work. Or is a database mandatory? It's not stated in the docs, and the ::check() after Auth::login works perfectly.

Thanks

0

There are 0 best solutions below