// client/src/utils/legacySocket.js
import SocketIO from "socket.io-client";
import { auth } from "../firebase/firebase.utils";

// Create once, reuse everywhere.
const legacySocket = SocketIO(import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "", {
  path: "/ws",
  withCredentials: true,
  autoConnect: false,
  auth: async (callback) => {
    const token = auth.currentUser && (await auth.currentUser.getIdToken());
    callback({ token });
  }
});

export default legacySocket;
