Chapter 5 · Practice 5 of 5
Validate every submission on the server as well
Why it matters
Client validation with required, type="email" and pattern gives fast feedback, but anyone can bypass it with the dev tools or a direct request.
Server Functions marked with 'use server' are reachable as public endpoints, so inside the function itself check:
- Authentication: who is calling.
- Authorization: whether they may change this specific record.
- Every field: parse the input with a schema library such as Zod to get typed data.
Return field errors to useActionState so the form can show them next to the right input.
Do
- Parse
FormDatawith a schema before using it - Check the user is allowed to change this specific record
Avoid
- Trusting hidden form fields such as
userIdorprice