Next.js Server Action writer
Generate type-safe Server Actions with Zod validation, auth guards, and structured error handling — all from a single prompt.
Ingredients
- Zod schema for input validation
- Auth check via getAuth() or clerkClient
- Structured return type: data | error
- revalidatePath / revalidateTag for cache
Steps
- 1Define the Zod schema matching your form fields.
- 2Wrap logic in try/catch; return typed errors.
- 3Call revalidatePath after mutation succeeds.
- 4Use useActionState in the client form component.