← Back to Docs
Recipe

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

  1. 1Define the Zod schema matching your form fields.
  2. 2Wrap logic in try/catch; return typed errors.
  3. 3Call revalidatePath after mutation succeeds.
  4. 4Use useActionState in the client form component.