Next.js · Middle · Question 37 of 75
In Next.js, how do you send only part of the DB data to the client so nothing extra (like a password hash) leaks?
- ✓Correct answer: Return DTOs with only the needed fields from the data access layer
- 2Pass the whole user object: React hides the extra fields
- 3Delete the extra fields in the client component after receiving them
Explanation
Everything in a client component's props is serialized into the HTML and RSC payload and visible in DevTools. A Data Access Layer that checks permissions and returns minimal DTOs is recommended. You can also use the taint API to forbid passing certain objects to the client.