I have a UseGuard
in my WebSocket. Actually, this guard is a JwtAuthGuard
that extends AuthGuard('jwt')
. The JwtAuthGuard
has a Strategy class called JwtStrategy
. In this class, I have a validate
method. In HTTP-based requests I return payload in this method. Then nestjs attach the payload to the req
. Here is my Strategy class:
@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;
}
}
I want to have access to context within validate
method in order to attach the payload to the WebSocket's body (or anything that I can have access to the payload). Any idea?