Next.js Server Actions
Create Server Actions for form submissions and mutations with explicit validation and security.
When to Use
- •Mutations co-located with App Router pages
- •Forms requiring server-side validation
- •CSRF protection requirements
Inputs
- •Form fields and validation rules
- •Redirect or revalidation behavior
- •CSRF strategy (token or double-submit cookie)
Instructions
- •Create a Server Action in the route or
actionsmodule. - •Validate inputs on the server.
- •Enforce CSRF protection for state-changing actions.
- •Return typed results and handle errors.
- •Use revalidation (
revalidatePath/revalidateTag) if needed.
Output
- •Server Action with validation, CSRF controls, and typed results.