Complete the code to import the Guard interface from NestJS.
import { [1] } from '@nestjs/common';
The CanActivate interface is used to create guards in NestJS.
Complete the code to implement the canActivate method in a guard.
canActivate(context: ExecutionContext): [1] { return true; }
The canActivate method must return a boolean to allow or deny access.
Fix the error in the guard class declaration.
export class AuthGuard implements [1] { }
Guards must implement the CanActivate interface to control access.
Fill both blanks to create a guard that denies access when user is not authenticated.
canActivate(context: ExecutionContext): [1] { const request = context.switchToHttp().getRequest(); return request.user [2] undefined; }
The method returns a boolean. It denies access if request.user is not set.
Fill all three blanks to create a guard that allows access only if user role is 'admin'.
canActivate(context: ExecutionContext): [1] { const request = context.switchToHttp().getRequest(); const user = request.user; return user?.role [2] [3]; }
The guard returns a boolean. It checks if user.role is exactly 'admin' to allow access.
