Bird
0
0

What is the main purpose of a guard in NestJS when protecting routes?

easy📝 Conceptual Q11 of 15
NestJS - Authentication
What is the main purpose of a guard in NestJS when protecting routes?
ATo decide if a request can access a route based on custom logic
BTo format the response data before sending it
CTo handle database connections automatically
DTo log every request made to the server
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of guards

    Guards in NestJS are designed to control access to routes by running custom logic before the route handler executes.
  2. Step 2: Identify the correct purpose

    Among the options, only deciding if a request can access a route matches the guard's role.
  3. Final Answer:

    To decide if a request can access a route based on custom logic -> Option A
  4. Quick Check:

    Guards control access = C [OK]
Quick Trick: Guards allow or block access before route runs [OK]
Common Mistakes:
  • Confusing guards with interceptors or middleware
  • Thinking guards modify response data
  • Assuming guards handle database tasks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes