check()) { // Get the authenticated user from the current guard $user = Auth::guard($guard)->user(); if ($user) { session('activeProfileType', get_class($user)); session('activeProfileId', $user->id); } return redirect()->route('main'); // Redirect to the main route } } return $next($request); } }