From 9bdab16a379f8af42c8dfc0aa63aef7245427235 Mon Sep 17 00:00:00 2001 From: Xavier Abad Date: Tue, 10 Feb 2026 16:51:06 +0100 Subject: [PATCH 1/2] fix: socket credentials --- src/services/sockets/socket.service.test.ts | 14 +++++-------- src/services/sockets/socket.service.ts | 22 +++++++++------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/services/sockets/socket.service.test.ts b/src/services/sockets/socket.service.test.ts index d1163c1fd..d1e75e2f1 100644 --- a/src/services/sockets/socket.service.test.ts +++ b/src/services/sockets/socket.service.test.ts @@ -94,16 +94,12 @@ describe('RealtimeService', () => { }); test.each([ - { env: 'production', reconnection: true, withCredentials: true, logs: false }, - { env: 'development', reconnection: true, withCredentials: false, logs: true }, + { isProduction: true, reconnection: true, withCredentials: true, logs: false }, + { isProduction: false, reconnection: true, withCredentials: false, logs: true }, ])( - 'When running in $env environment, then it adjusts reconnection=$reconnection, withCredentials=$withCredentials and logging=$logs', - ({ env, reconnection, withCredentials, logs }) => { - vi.spyOn(envService, 'getVariable').mockImplementation((key: string) => { - if (key === 'nodeEnv') return env; - if (key === 'notifications') return 'https://notifications.example.com'; - return ''; - }); + 'When running in isProduction=$isProduction environment, then it adjusts reconnection=$reconnection, withCredentials=$withCredentials and logging=$logs', + ({ isProduction, reconnection, withCredentials, logs }) => { + vi.spyOn(envService, 'isProduction').mockReturnValue(isProduction); service.init(); diff --git a/src/services/sockets/socket.service.ts b/src/services/sockets/socket.service.ts index 20ed76bb8..380c93132 100644 --- a/src/services/sockets/socket.service.ts +++ b/src/services/sockets/socket.service.ts @@ -18,7 +18,7 @@ export default class RealtimeService { } init(onConnected?: () => void): void { - if (!isProduction()) { + if (!envService.isProduction()) { console.log('[REALTIME]: CONNECTING...'); } @@ -27,18 +27,18 @@ export default class RealtimeService { token: getToken(), }, reconnection: true, - withCredentials: isProduction(), + withCredentials: envService.isProduction(), }); this.socket.on('connect', () => { - if (!isProduction()) { + if (!envService.isProduction()) { console.log('[REALTIME]: CONNECTED WITH ID', this.socket?.id); } onConnected?.(); }); this.socket.on('event', (data) => { - if (!isProduction()) { + if (!envService.isProduction()) { console.log('[REALTIME] EVENT RECEIVED:', JSON.stringify(data, null, 2)); } @@ -52,13 +52,13 @@ export default class RealtimeService { }); this.socket.on('disconnect', (reason) => { - if (!isProduction()) { + if (!envService.isProduction()) { console.log('[REALTIME] DISCONNECTED:', reason); } }); this.socket.on('connect_error', (error) => { - if (!isProduction()) console.error('[REALTIME] CONNECTION ERROR:', error); + if (!envService.isProduction()) console.error('[REALTIME] CONNECTION ERROR:', error); }); } @@ -70,14 +70,14 @@ export default class RealtimeService { } onEvent(cb: (data: any) => void): () => void { - if (!isProduction()) { + if (!envService.isProduction()) { console.log('[REALTIME] Registering event handler. Total handlers:', this.eventHandlers.size + 1); } this.eventHandlers.add(cb); return () => { - if (!isProduction()) { + if (!envService.isProduction()) { console.log('[REALTIME] Removing event handler. Remaining handlers:', this.eventHandlers.size - 1); } this.eventHandlers.delete(cb); @@ -85,7 +85,7 @@ export default class RealtimeService { } removeAllListeners() { - if (!isProduction()) { + if (!envService.isProduction()) { console.log('[REALTIME] Clearing all event handlers'); } this.eventHandlers.clear(); @@ -101,10 +101,6 @@ export default class RealtimeService { } } -function isProduction(): boolean { - return envService.getVariable('nodeEnv') === 'production'; -} - function getToken(): string { return localStorageService.get('xNewToken') as string; } From 3e9fbb4788b1e8bcdc385fafbf3d9f07daf164fd Mon Sep 17 00:00:00 2001 From: Xavier Abad Date: Tue, 10 Feb 2026 17:17:29 +0100 Subject: [PATCH 2/2] feat: add console log --- src/services/sockets/socket.service.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/services/sockets/socket.service.ts b/src/services/sockets/socket.service.ts index 380c93132..8f590fee8 100644 --- a/src/services/sockets/socket.service.ts +++ b/src/services/sockets/socket.service.ts @@ -38,9 +38,7 @@ export default class RealtimeService { }); this.socket.on('event', (data) => { - if (!envService.isProduction()) { - console.log('[REALTIME] EVENT RECEIVED:', JSON.stringify(data, null, 2)); - } + console.log('[REALTIME] EVENT RECEIVED:', JSON.stringify(data, null, 2)); this.eventHandlers.forEach((handler) => { try {