From a0da6c26a3e4c7929b559ef543c1e234c6ad0c4e Mon Sep 17 00:00:00 2001 From: Ales Menzel Date: Mon, 7 Aug 2023 13:47:24 +0200 Subject: [PATCH] use own interface for Socket request to allow extending the interface with custom properties without polluting the IncomingMessage type which is also used by Express/Passport Using socket.io with passport middlewares causes issues when using the same 'userProperty' key for both - by extending IncomingMessage { user: Express.user } we break passport's isAuthenticated() function which returns never in the else case since the IncomingMessage always has a user property on itself. To fix this, I believe we should be able to extend only the request type inside socket.io -> SocketRequest. --- lib/index.ts | 2 +- lib/socket.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index f5cfedf278..910c7b68ab 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1136,4 +1136,4 @@ export { BroadcastOperator, RemoteSocket, }; -export { Event } from "./socket"; +export { Event, SocketRequest } from "./socket"; diff --git a/lib/socket.ts b/lib/socket.ts index 0d065c0263..71a65a3235 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -87,6 +87,8 @@ export const RESERVED_EVENTS: ReadonlySet = new Set< "removeListener", ]); +export interface SocketRequest extends IncomingMessage {} + /** * The handshake details */ @@ -990,7 +992,7 @@ export class Socket< /** * A reference to the request that originated the underlying Engine.IO Socket. */ - public get request(): IncomingMessage { + public get request(): SocketRequest { return this.client.request; }