You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using socket.io websocket server, following NestJS documentation.
I need to identify users by session token by passing session token to connection url (security reasons).
So I want to check session token in websocket server connection method and disconnect websockets with bad sessions.
There is a method in NestJS Gateway: handleConnection. This method triggers only when socket.io client send specific handshake message!!!. I want make handleConnection to trigger when client just connected without sending specific socket.io protocol messages! There are no way to make this in NestJS.
So I tried to make my own method. And at this point bug appeared.
@WebSocketGateway(3000)
export class AppGateway implements OnGatewayInit {
constructor() {}
@WebSocketServer()
public readonly server: Server;
afterInit() {
this.server.engine // => undefined
this.server.server.engine // => typescript error: "server" value does not exist on type Server
(this.server as any).server.engine // engine exists!
(this.server as any).server.engine.on('connection', () => {
console.log('client enstablished connection!'); // it triggers when client connect!
})
}
}
Bug Conclusion: There is no way to access server.engine. It is undefined. Engine accessed by server.server.engine. But there are no type for this.
P.S. about handleConnection method, I think this is new feature request or something like this. It probably not a bug.
Is there an existing issue for this?
Current behavior
I am using socket.io websocket server, following NestJS documentation.
I need to identify users by session token by passing session token to connection url (security reasons).
So I want to check session token in websocket server connection method and disconnect websockets with bad sessions.
There is a method in NestJS Gateway:
handleConnection
. This method triggers only when socket.io client send specific handshake message!!!. I want makehandleConnection
to trigger when client just connected without sending specific socket.io protocol messages! There are no way to make this in NestJS.So I tried to make my own method. And at this point bug appeared.
Bug Conclusion: There is no way to access
server.engine
. It is undefined. Engine accessed byserver.server.engine
. But there are no type for this.P.S. about
handleConnection
method, I think this isnew feature request
or something like this. It probably not a bug.Minimum reproduction code
https://codesandbox.io/s/amazing-aj-qoljj4?file=/src/app.gateway.ts
Steps to reproduce
No response
Expected behavior
server.engine
should exist onServer
type.At this moment,
engine
accessed byserver.server.engine
. Butserver.server
type does not exist.Package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other package
No response
NestJS version
No response
Packages versions
Node.js version
16.14.2
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: