Bird
0
0

What is the main purpose of the canActivate method in a NestJS guard?

easy📝 Conceptual Q11 of 15
NestJS - Guards
What is the main purpose of the canActivate method in a NestJS guard?
ATo format the response data
BTo handle database connections
CTo decide if a request should be allowed or denied access
DTo log user activity
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of guards in NestJS

    Guards are used to control access to routes by allowing or denying requests.
  2. Step 2: Identify the function of canActivate

    The canActivate method returns true or false to allow or deny access.
  3. Final Answer:

    To decide if a request should be allowed or denied access -> Option C
  4. Quick Check:

    Guard access control = canActivate returns true/false [OK]
Quick Trick: Remember: canActivate returns true to allow access [OK]
Common Mistakes:
  • Confusing canActivate with response formatting
  • Thinking canActivate handles database logic
  • Assuming canActivate logs user actions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes