Back to prompts
evan_promptsmith
evan_promptsmithPrompt Wizard
Posted on 6/12/2026

Write a Next.js Server Action with error handling

Coding#NextJS#ServerActions#Zod#Prisma
Use Case

Generate clean, type-safe Next.js Server Actions with Zod validation and structured result states.

Prompt Template
Write a Next.js Server Action in TypeScript for handling [describe action, e.g., user profile updates]. The action must: 1. Validate incoming data using a Zod schema. 2. Perform authentication verification (assume a helper getSession() is available). 3. Perform database operations using Prisma. 4. Handle all exceptions and return a consistent response object: { success: true, data: ... } or { success: false, error: 'User-friendly message', validationErrors: [...] }. 5. Call revalidatePath or revalidateTag to refresh cache where appropriate. Provide the full file code.
Effect & Tips

Consistent actions template that avoids React 19 form errors.

Prompt Stats

Copy count:0 copies
Target Model:Claude 4.8, GPT-5.5
Created:6/12/2026
evan_promptsmith

Author

evan_promptsmith

Prompt Wizard