This commit is contained in:
2026-01-29 02:39:21 -05:00
parent 6f971d1b50
commit 172ac4a48d
2 changed files with 15 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ export function SocketProvider({ children }) {
useEffect(() => {
// Only connect if user is authenticated
if (!user || !token) {
console.log('⏳ Waiting for authentication...', { user: !!user, token: !!token });
if (socket) {
socket.disconnect();
setSocket(null);
@@ -28,10 +29,14 @@ export function SocketProvider({ children }) {
return;
}
console.log('🔄 Initializing socket connection...');
// Determine backend URL
const backendUrl = import.meta.env.VITE_API_URL ||
(import.meta.env.DEV ? 'http://localhost:4000' : window.location.origin);
console.log('🌐 Connecting to:', backendUrl);
// Create socket connection with JWT authentication
const newSocket = io(backendUrl, {
auth: {
@@ -53,7 +58,8 @@ export function SocketProvider({ children }) {
});
newSocket.on('connect_error', (error) => {
console.error('Socket connection error:', error.message);
console.error('Socket connection error:', error.message);
console.error(' Error details:', error);
});
setSocket(newSocket);