NestJS - GuardsWhat will happen if a role-based guard's canActivate method returns false in NestJS?AThe request proceeds to the next middlewareBThe user is redirected to the login page automaticallyCThe server crashes with an errorDThe request is denied and a 403 Forbidden response is sentCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand canActivate return value meaningReturning false from canActivate denies access to the route.Step 2: Identify NestJS default behavior on denialNestJS sends a 403 Forbidden HTTP response when access is denied.Final Answer:The request is denied and a 403 Forbidden response is sent -> Option DQuick Check:canActivate false = 403 Forbidden response [OK]Quick Trick: False from canActivate means 403 Forbidden response [OK]Common Mistakes:Thinking request continues despite falseAssuming server crashes on falseExpecting automatic redirects
Master "Guards" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Authentication - Local strategy (username/password) - Quiz 8hard Database with Prisma - CRUD with Prisma - Quiz 12easy Database with Prisma - Why Prisma offers type-safe database access - Quiz 1easy Interceptors - Interceptor interface - Quiz 9hard Middleware - Why middleware processes requests before handlers - Quiz 14medium Middleware - Global middleware - Quiz 15hard Pipes - Custom pipes - Quiz 14medium Pipes - Why pipes transform and validate input - Quiz 10hard Pipes - Pipe binding (parameter, method, controller, global) - Quiz 4medium Pipes - File validation pipe - Quiz 5medium