Complete the code to import the JWT guard from NestJS.
import { [1] } from '@nestjs/passport';
The correct import is AuthGuard from '@nestjs/passport' which is used to create JWT guards.
Complete the code to create a JWT authentication guard class.
export class JwtAuthGuard extends [1]('jwt') {}
The guard class extends AuthGuard with the strategy name 'jwt'.
Fix the error in the guard usage in a controller method decorator.
@UseGuards([1]) getProfile() { return 'profile data'; }
The guard class is passed without parentheses in the @UseGuards decorator.
Fill both blanks to implement a custom canActivate method that logs before calling the base guard.
async canActivate(context: ExecutionContext): Promise<boolean> {
console.log([1]);
return (await super.canActivate([2])) as boolean;
}The log message is a string, and the context object is passed to the base canActivate method.
Fill all three blanks to extract the user from the request inside the guard.
const request = context.switchToHttp().get[1](); const user = request.[2]; return user !== [3];
The method to get the HTTP request is getRequest(). The user is accessed via request.user. The guard returns false if user is null.