Bird
0
0

What will be the result of this NestJS controller method when called with a valid JWT token? ```typescript @UseGuards(AuthGuard('jwt')) @Get('data') getData() { return { data: 'Secure data' }; } ```

medium📝 Predict Output Q5 of 15
NestJS - Authentication
What will be the result of this NestJS controller method when called with a valid JWT token? ```typescript @UseGuards(AuthGuard('jwt')) @Get('data') getData() { return { data: 'Secure data' }; } ```
AReturns a 403 Forbidden error
BReturns an empty object {}
CReturns { data: 'Secure data' }
DReturns a 500 Internal Server Error
Step-by-Step Solution
Solution:
  1. Step 1: Confirm valid token bypasses guard

    With a valid JWT token, the AuthGuard allows access to the method.
  2. Step 2: Identify method return value

    The method returns the object { data: 'Secure data' } as response.
  3. Final Answer:

    Returns { data: 'Secure data' } -> Option C
  4. Quick Check:

    Valid token returns data object [OK]
Quick Trick: Valid JWT token grants access and returns data [OK]
Common Mistakes:
  • Expecting error with valid token
  • Thinking it returns empty object
  • Assuming server error occurs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes