Recall & Review
beginner
What is the purpose of a JWT authentication guard in NestJS?
A JWT authentication guard protects routes by checking if the incoming request has a valid JWT token. It ensures only authenticated users can access certain parts of the app.
Click to reveal answer
intermediate
How does a JWT authentication guard verify a token in NestJS?
It extracts the token from the request header, then uses a JWT service to verify the token's signature and expiration. If valid, it allows access; otherwise, it denies it.
Click to reveal answer
intermediate
Which NestJS interface must a JWT guard implement?
It must implement the CanActivate interface, which requires a canActivate method to decide if the request should proceed.
Click to reveal answer
beginner
What happens if the JWT token is missing or invalid in a NestJS JWT guard?
The guard throws an UnauthorizedException, which stops the request and sends a 401 Unauthorized response to the client.
Click to reveal answer
beginner
How do you apply a JWT authentication guard to a route in NestJS?
You use the @UseGuards() decorator on the controller or route handler and pass the JWT guard class to it.Click to reveal answer
What does a JWT authentication guard check in a NestJS app?
✗ Incorrect
A JWT authentication guard checks the presence and validity of a JWT token in the request.
Which method must a NestJS guard implement?
✗ Incorrect
The CanActivate interface requires the canActivate method to decide if a request can proceed.
Where is the JWT token usually found in an HTTP request for NestJS guards?
✗ Incorrect
JWT tokens are commonly sent in the Authorization header as a Bearer token.
What response status code does NestJS send if JWT guard denies access?
✗ Incorrect
UnauthorizedException triggers a 401 Unauthorized response when access is denied.
How do you protect a NestJS route with a JWT guard?
✗ Incorrect
The @UseGuards decorator applies the JWT guard to routes or controllers.
Explain how a JWT authentication guard works in NestJS to protect routes.
Think about the steps from receiving a request to deciding access.
You got /4 concepts.
Describe how to apply a JWT authentication guard to a NestJS controller or route.
Focus on the decorator usage in NestJS.
You got /4 concepts.