check()) { abort(403, 'Unauthorized - No active authentication found'); } // Get the authenticated user from the active guard $user = Auth::guard($activeGuard)->user(); // Set the default guard to use for this request Auth::shouldUse($activeGuard); // Get the channel name from the request $channelName = $request->input('channel_name'); // Attempt to authorize the channel try { $result = Broadcast::auth($request); return response()->json($result); } catch (\Exception $e) { \Log::error('Broadcasting authentication failed', [ 'guard' => $activeGuard, 'user_id' => $user->id, 'channel' => $channelName, 'error' => $e->getMessage() ]); abort(403, 'Unauthorized'); } } }