bugfix
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user