NestJS - GuardsWhat is wrong with this usage of JwtAuthGuard? ```typescript @Get('info') @UseGuards() getInfo() { return { info: 'details' }; } ```A@UseGuards() is missing the JwtAuthGuard class insideB@UseGuards() cannot be used on GET methodsCgetInfo method must be asyncDJwtAuthGuard must be imported from '@nestjs/jwt'Check Answer
Step-by-Step SolutionSolution:Step 1: Check @UseGuards decorator usage@UseGuards() requires guard classes as arguments.Step 2: Identify missing guard classHere, JwtAuthGuard is not passed inside @UseGuards().Final Answer:@UseGuards() is missing the JwtAuthGuard class inside -> Option AQuick Check:@UseGuards needs guard class argument [OK]Quick Trick: Always pass guard class inside @UseGuards() [OK]Common Mistakes:Leaving @UseGuards emptyThinking @UseGuards can't be on GETAssuming method must be async unnecessarily
Master "Guards" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Authentication - Session-based authentication - Quiz 2easy Database with Prisma - Schema definition - Quiz 15hard Database with TypeORM - Migrations - Quiz 1easy Guards - Reflector and custom decorators - Quiz 10hard Guards - Guard interface (canActivate) - Quiz 9hard Interceptors - Response transformation - Quiz 5medium Interceptors - Cache interceptor - Quiz 1easy Interceptors - Interceptor interface - Quiz 5medium Middleware - Global middleware - Quiz 11easy Pipes - Pipe binding (parameter, method, controller, global) - Quiz 7medium