B. AuthGuard cannot be used with WebSocket gateways
C. @UsePipes must be placed before @UseGuards
D. ParseIntPipe cannot parse a string directly without conversion
Solution
Step 1: Check pipe compatibility with data type
ParseIntPipe expects a value that can be parsed to integer, but data is a string that may not convert properly.
Step 2: Validate other decorator usage
AuthGuard is valid for WebSocket guards, and decorator order does not cause error here. Returning Promise is optional.
Final Answer:
ParseIntPipe cannot parse a string directly without conversion -> Option D
Quick Check:
ParseIntPipe needs numeric input = D [OK]
Hint: Pipes must match expected input types [OK]
Common Mistakes:
Assuming guards can't be used on WebSocket
Thinking decorator order always matters
Believing return type must be Promise
5. You want to ensure only authenticated users can send messages and that the message payload is a valid JSON object with a 'text' property. Which combination of guard and pipe setup is best in a NestJS WebSocket gateway?
hard
A. Use @UseGuards(AuthGuard) to check authentication and @UsePipes(ValidationPipe) with a DTO validating 'text' property
B. Use @UsePipes(AuthGuard) to check authentication and @UseGuards(ValidationPipe) for payload validation
C. Use @UseGuards(AuthGuard) only, and validate payload manually inside the handler
D. Use @UsePipes(ValidationPipe) only, assuming it checks authentication too
Solution
Step 1: Assign correct roles to guard and pipe
Guards handle authentication and authorization, so AuthGuard should be used as a guard.
Step 2: Use ValidationPipe with DTO for payload validation
ValidationPipe validates and transforms incoming data using a DTO that checks the 'text' property.
Step 3: Evaluate other options
Swapping guards and pipes misuses decorators; using guards only requires manual payload validation lacking automation; using pipes only misses authentication checks.
Final Answer:
Use @UseGuards(AuthGuard) to check authentication and @UsePipes(ValidationPipe) with a DTO validating 'text' property -> Option A
Quick Check:
Guard for auth + Pipe for validation = B [OK]
Hint: Guards for auth, pipes for data validation [OK]
Common Mistakes:
Swapping guards and pipes roles
Skipping automatic validation
Assuming pipes handle authentication
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.