我的 WebSocket 中有一个UseGuard。实际上,这个守卫是一个JwtAuthGuard延伸的AuthGuard('jwt')。JwtAuthGuard有一个名为 Strategy 的类JwtStrategy。在这堂课中,我有一个validate方法。在基于 HTTP 的请求中,我在此方法中返回有效负载。然后 nestjs 将有效负载附加到req. 这是我的策略课:
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private authConfigService: AuthConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: authConfigService.JWT_SECRET,
});
}
async validate(payload: any) {
return payload;
}
}
我想访问方法 中的上下文validate,以便将有效负载附加到 WebSocket 的主体(或我可以访问有效负载的任何东西)。任何的想法?