diff --git a/packages/backend/src/auth/session/websocketSession.service.ts b/packages/backend/src/auth/session/websocketSession.service.ts index 10af73c2..c6c248cc 100644 --- a/packages/backend/src/auth/session/websocketSession.service.ts +++ b/packages/backend/src/auth/session/websocketSession.service.ts @@ -7,16 +7,21 @@ export class WebsocketSessionService { constructor(private readonly sessionStore: MemoryStore) {} async getAuthenticatedUser(socket: Socket) { - const cookieValue = websocketCookieParse(socket); - const session = await this.getSession(cookieValue); - return session ? session.passport.user : undefined; + try { + const cookieValue = websocketCookieParse(socket); + const session = await this.getSession(cookieValue); + return session ? session.passport.user : null; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (e) { + return null; + } } private getSession(cookieValue: string) { - return new Promise((resolve) => { + return new Promise((resolve) => { this.sessionStore.get(cookieValue, (err: Error, session) => { if (err || !session) { - resolve(undefined); + resolve(null); } resolve(session as PassportSession); });