From 7363c4c692b5dfa197b6921566cac04eea2c7543 Mon Sep 17 00:00:00 2001 From: chamiakJ Date: Tue, 22 Apr 2025 21:19:13 +0530 Subject: [PATCH] Refactor socket session user structure and update user ID retrieval - Changed the user structure in ISocketSession to include an object with an 'id' property. - Updated the getLoggedInUserIdFromSocket function to return the user ID directly from the new structure. --- worklenz-backend/src/interfaces/socket-session.ts | 2 +- worklenz-backend/src/socket.io/util.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/worklenz-backend/src/interfaces/socket-session.ts b/worklenz-backend/src/interfaces/socket-session.ts index 9e5936ed..fea96a34 100644 --- a/worklenz-backend/src/interfaces/socket-session.ts +++ b/worklenz-backend/src/interfaces/socket-session.ts @@ -1,5 +1,5 @@ export interface ISocketSession { session?: { - passport?: { user?: string; } + passport?: { user?: { id: string } } } } diff --git a/worklenz-backend/src/socket.io/util.ts b/worklenz-backend/src/socket.io/util.ts index ee274e02..a9732521 100644 --- a/worklenz-backend/src/socket.io/util.ts +++ b/worklenz-backend/src/socket.io/util.ts @@ -15,7 +15,10 @@ export function log_error(error: any) { export function getLoggedInUserIdFromSocket(socket: Socket): string | null { const {session} = socket.request as ISocketSession; - return session?.passport?.user || null; + if (session?.passport?.user?.id) { + return session.passport.user.id; + } + return null; } export async function notifyProjectUpdates(socket: Socket, taskId: string) {