Bird
0
0

How can you modify the LocalStrategy to include additional user data in the validate method's return value?

hard📝 Application Q9 of 15
NestJS - Authentication
How can you modify the LocalStrategy to include additional user data in the validate method's return value?
AReturn a boolean and fetch user data later
BModify the authService to return only user ID
CThrow an exception with extra data attached
DReturn a custom object with user data after validation
Step-by-Step Solution
Solution:
  1. Step 1: Understand validate method flexibility

    The validate method can return any object representing the authenticated user.
  2. Step 2: Customize return value

    Returning a custom object with additional user data allows attaching more info to the request.
  3. Final Answer:

    Return a custom object with user data after validation -> Option D
  4. Quick Check:

    Return custom user object to include extra data [OK]
Quick Trick: Return custom user object with extra info [OK]
Common Mistakes:
  • Returning only boolean instead of user object
  • Throwing exceptions to pass data
  • Modifying service to limit data unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes