Recall & Review
beginner
What is the purpose of guards in NestJS?
Guards in NestJS control whether a request can proceed to the route handler by checking conditions like authentication or roles.
Click to reveal answer
beginner
How do you apply multiple guards to a single route in NestJS?
You apply multiple guards by passing them as arguments to the @UseGuards() decorator, like @UseGuards(Guard1, Guard2).
Click to reveal answer
intermediate
What happens if one guard in a combined set returns false?
If any guard returns false, NestJS stops and denies access to the route, so all guards must pass for the request to proceed.
Click to reveal answer
intermediate
Can you combine guards globally and locally in NestJS?
Yes, you can apply guards globally for all routes and also locally on specific controllers or routes. Local guards run after global ones.
Click to reveal answer
beginner
Example: How to combine AuthGuard and RolesGuard on a route?
Use @UseGuards(AuthGuard, RolesGuard) above the route handler. This checks authentication first, then user roles before allowing access.
Click to reveal answer
How do you apply multiple guards to a NestJS route?
✗ Incorrect
You pass multiple guards as arguments to a single @UseGuards() decorator, like @UseGuards(Guard1, Guard2).
What happens if one guard returns false in a combined guard set?
✗ Incorrect
If any guard returns false, NestJS denies access and stops processing the request.
Can you combine global and local guards in NestJS?
✗ Incorrect
Global guards run first, then local guards run on specific controllers or routes.
Which decorator is used to apply guards in NestJS?
✗ Incorrect
@UseGuards() is the decorator to apply guards to routes or controllers.
What is a common use case for combining AuthGuard and RolesGuard?
✗ Incorrect
AuthGuard checks if the user is logged in, RolesGuard checks if the user has the right permissions.
Explain how NestJS processes multiple guards applied to a route.
Think about a security checkpoint where multiple checks must pass.
You got /3 concepts.
Describe how to apply guards globally and locally in NestJS and how they interact.
Consider a building with a main gate (global) and room doors (local).
You got /3 concepts.