A. AuthGuard should receive strategy name as string, not class
B. Missing @Controller decorator
C. getProfile method must be async
D. AuthGuard cannot be used with @Get
Solution
Step 1: Check AuthGuard parameter
AuthGuard expects a string with the strategy name, e.g., 'local', not the strategy class.
Step 2: Confirm correct usage
Correct usage is @UseGuards(AuthGuard('local')), passing the strategy name as a string.
Final Answer:
AuthGuard should receive strategy name as string, not class -> Option A
Quick Check:
AuthGuard('strategyName') not class [OK]
Hint: Pass strategy name string to AuthGuard [OK]
Common Mistakes:
Passing strategy class instead of string
Forgetting to import AuthGuard
Assuming method must be async
5. You want to protect a NestJS route so only logged-in users can access it using Passport.js. Which combination correctly sets this up?
1. Create a JWT strategy class
2. Use @UseGuards(AuthGuard('jwt')) on the route
3. Implement validate() method in strategy
4. Call AuthGuard('local') on the route
Which steps should you follow?
hard
A. All steps 1, 2, 3, and 4
B. Steps 1, 2, and 3 only
C. Steps 1 and 4 only
D. Steps 2 and 4 only
Solution
Step 1: Understand JWT strategy usage
To protect routes with JWT, create a JWT strategy and implement validate() to verify tokens.
Step 2: Apply AuthGuard with 'jwt'
Use @UseGuards(AuthGuard('jwt')) on routes to enforce JWT authentication.
Step 3: Exclude local strategy for JWT protection
Using AuthGuard('local') is for login, not for protecting routes after login.
Final Answer:
Steps 1, 2, and 3 only -> Option B
Quick Check:
JWT strategy + AuthGuard('jwt') + validate() [OK]
Hint: Use JWT strategy and AuthGuard('jwt') to protect routes [OK]
Common Mistakes:
Using local strategy guard to protect routes
Skipping validate() method in strategy
Applying AuthGuard without strategy name
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.