false, what is the immediate effect on the client connection or message handling?When a WebSocket guard returns false, NestJS prevents the message handler from running but keeps the connection alive. It does not close the connection or throw errors automatically.
import { SubscribeMessage, WebSocketGateway, MessageBody } from '@nestjs/websockets'; import { UsePipes, ValidationPipe } from '@nestjs/common'; @WebSocketGateway() export class ChatGateway { @SubscribeMessage('message') @UsePipes(new ValidationPipe()) handleMessage(@MessageBody() data: any) { return data; } }
The @UsePipes decorator must be placed directly above the method it affects, after the @SubscribeMessage decorator. Passing pipes as parameters or applying them inside the method is not the NestJS pattern.
The guard checks client.handshake.auth.token, but if the client sends the token inside the message payload instead, the guard will not find it and always return false or true incorrectly.
'hello', what will the server return?The pipe class AppendPipe is passed directly to @UsePipes without instantiation. NestJS expects an instance or a class reference, but for classes it creates instances automatically only if passed as a class reference without parentheses. Here, passing the class without parentheses is correct, but if the pipe requires constructor parameters or is not injectable, it will fail.
In this case, since AppendPipe is injectable and has no constructor parameters, NestJS will instantiate it. So the correct output is 'hello world'.
In NestJS, guards run first to decide if the request or message should proceed. Only if guards allow it do pipes run to transform or validate data before the handler executes.