Bird
0
0

What will happen if a role-based guard's canActivate method returns false in NestJS?

medium📝 Predict Output Q5 of 15
NestJS - Guards
What will happen if a role-based guard's canActivate method returns false in NestJS?
AThe request proceeds to the next middleware
BThe user is redirected to the login page automatically
CThe server crashes with an error
DThe request is denied and a 403 Forbidden response is sent
Step-by-Step Solution
Solution:
  1. Step 1: Understand canActivate return value meaning

    Returning false from canActivate denies access to the route.
  2. Step 2: Identify NestJS default behavior on denial

    NestJS sends a 403 Forbidden HTTP response when access is denied.
  3. Final Answer:

    The request is denied and a 403 Forbidden response is sent -> Option D
  4. Quick Check:

    canActivate false = 403 Forbidden response [OK]
Quick Trick: False from canActivate means 403 Forbidden response [OK]
Common Mistakes:
  • Thinking request continues despite false
  • Assuming server crashes on false
  • Expecting automatic redirects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes