NestJS - GuardsWhich of the following is the correct method signature for a guard's access check in NestJS?AhandleRequest(req: Request): booleanBcheckAccess(context: Context): voidCcanActivate(context: ExecutionContext): boolean | Promise<boolean>DvalidateUser(user: User): booleanCheck Answer
Step-by-Step SolutionSolution:Step 1: Recall the guard interface methodThe guard interface requires a canActivate method with ExecutionContext parameter returning boolean or Promise.Step 2: Eliminate incorrect signaturesOther methods and parameters do not match the NestJS guard pattern.Final Answer:canActivate(context: ExecutionContext): boolean | Promise -> Option CQuick Check:Guard method signature = B [OK]Quick Trick: Guard method is canActivate with ExecutionContext [OK]Common Mistakes:Using wrong method namesMissing ExecutionContext parameterReturning void instead of boolean
Master "Guards" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Authentication - Local strategy (username/password) - Quiz 8hard Authentication - Why authentication secures NestJS APIs - Quiz 13medium Database with Prisma - CRUD with Prisma - Quiz 6medium Database with Prisma - CRUD with Prisma - Quiz 8hard Database with Prisma - Prisma setup in NestJS - Quiz 9hard Guards - Reflector and custom decorators - Quiz 14medium Interceptors - Exception mapping interceptor - Quiz 11easy Pipes - Custom pipes - Quiz 10hard Pipes - Custom pipes - Quiz 12easy Pipes - Custom pipes - Quiz 11easy