We had the following code to logout and log back in a user, which works with database sessions in Laravel 8. But after switching to cookie sessions its not longer functioning. It now only logs the user out, not back in again.
public function switchUser($user_id, Request $request)
{
$user = User::find($user_id);
Auth::logout();
Auth::login($user);
return redirect('/');
}
How can we fix this?
UPDATE
We updated SESSION_DRIVER from 'database' > 'cookie'
After 7 months of trying to fix this we have found the issue. This call was originally in the api.php routes file. Moving it into the web.php routes file has fixed the issue.
I can only imagine this is because the API routes are stateless by default, so this was effecting the login and logout.
Not entirely related to the original problem, but this fixed it for us.