@带有防护装置的nestjs/WebSocket使用host.setType失败

@带有防护装置的nestjs/WebSocket使用host.setType失败,websocket,nestjs,Websocket,Nestjs,我正在尝试向nestJs WebSocket添加JWT身份验证 我能够从客户端连接并发送标题 但是,当我使用保护设置nestJs WebSocket时,会出现错误TypeError:host.setType不是函数。 错误源于ws-proxy.js ExecutionContextHost的返回值没有名为setType的属性/方法,而是在第27行:使用它 我的Guard.ts文件如下 import { CanActivate, ExecutionContext, Injectable } fr

我正在尝试向nestJs WebSocket添加JWT身份验证
我能够从客户端连接并发送标题
但是,当我使用保护设置nestJs WebSocket时,会出现错误
TypeError:host.setType不是函数。

错误源于ws-proxy.js
ExecutionContextHost
的返回值没有名为
setType
的属性/方法,而是在第27行:使用它

我的Guard.ts文件如下

import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import * as configs from 'config';
import { Socket } from 'socket.io';
import { JwtService } from '@nestjs/jwt';
import { JwtPayload } from '../jwt-payload.interface';
import { WsException } from '@nestjs/websockets';

@Injectable()
export class JwtGuard implements CanActivate {
  constructor(private readonly jwtService: JwtService) { }

  async canActivate(context: ExecutionContext): Promise<boolean> {

    try {
      const client: Socket = context.switchToWs().getClient<Socket>();
      const authHeader: string = client.handshake.headers.authorization;
      const authToken = authHeader.substring(7, authHeader.length);
      const jwtPayload: JwtPayload = await this.jwtService.verifyAsync(authToken, configs.get('JWT.publicKey'));
      const user: any = this.validateUser(jwtPayload);

      context.switchToWs().getData().user = user;
      return Boolean(user);
    } catch (err) {
      throw new WsException(err.message);
    }
  }

  validateUser(payload: JwtPayload): any {
    return payload;
  }
}


有没有人遇到过这样的错误以及如何解决它?

发现问题,在
“@nestjs/websockets”:“^6.8.2”
&
“@nestjs/core”:“^6.0.0”,
之间存在包冲突。我需要升级所有@nestjs包

发现问题,
“@nestjs/websockets”:“^6.8.2”
“@nestjs/core”:“^6.0.0”,
。我需要升级所有@nestjs包

你能解释一下升级是什么意思吗?如何升级?我有同样的issue@nestjs/websockets&@nestjs/core或多或少需要在同一个版本上,在我的例子6.8.2中,你能解释一下升级是什么意思吗?如何升级?我有同样的issue@nestjs/websockets&@nestjs/core或多或少需要在同一个版本上,在我的例子6.8.2中,我正在尝试实现相同的功能,但是如何在客户端套接字和标头中连接?我正在添加选项对象{header:{Authorization:Bearer…}},但是没有办法获得…我正在尝试完成相同的操作,但是如何在客户端套接字中连接头?我正在添加选项对象{header:{Authorization:Bearer…}},但是没有办法获得。。。
import { SubscribeMessage, WebSocketGateway } from '@nestjs/websockets';
import { Socket } from 'socket.io';
import { UseGuards} from '@nestjs/common';
import { JwtGuard } from '../../../common/authentication/jwt-guard/jwt.guard';

@UseGuards(JwtGuard)
@WebSocketGateway()
export class ContractGateway {
  @SubscribeMessage('message')
  handleMessage(client: Socket, payload: any): Boolean {
    return true;
  }
}