Bird
0
0

You want to hide the user's password field from all API responses using response transformation. Which approach is best in NestJS?

hard📝 state output Q15 of 15
NestJS - Interceptors
You want to hide the user's password field from all API responses using response transformation. Which approach is best in NestJS?
ACreate an interceptor that maps the response and deletes the password field
BModify the database schema to exclude password
CUse a middleware to filter out password from requests
DSend password as null in the controller methods
Step-by-Step Solution
Solution:
  1. Step 1: Understand response transformation goal

    We want to remove sensitive info from outgoing responses, not database or requests.
  2. Step 2: Choose best NestJS method

    Interceptors can transform responses globally, ideal for removing password fields before sending.
  3. Step 3: Evaluate other options

    Modifying DB schema or middleware won't affect response data; setting password null in controllers is repetitive.
  4. Final Answer:

    Create an interceptor that maps the response and deletes the password field -> Option A
  5. Quick Check:

    Use interceptor to hide sensitive response data [OK]
Quick Trick: Use interceptor to remove sensitive fields from responses [OK]
Common Mistakes:
  • Trying to filter password in middleware (affects requests)
  • Changing database schema instead of response
  • Manually nulling password in every controller

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes