5 Server Action Mistakes That Ruin Your Next.js App ❌

Coding in Flow Guide 1 years ago

Description

Are you making these 5 common mistakes when using server actions in Next.js/React 19? If yes, your app might have security holes and bugs.

Starting code: https://github.com/codinginflow/server-actions-mistakes/tree/Starting-point
Final code: https://github.com/codinginflow/server-actions-mistakes

⭐ Get my full-stack Next.js with Express & TypeScript course: https://codinginflow.com/nextjs
✅ Get my free React Best Practices course: https://www.codinginflow.com/reactbestpractices
💌 Join my newsletter for regular web dev tips: https://codinginflow.com/newsletter
💬 Join our developer community on Discord: https://codinginflow.com/discord

📣 Follow Coding in Flow on social media:
Twitter: https://twitter.com/codinginflow
Instagram: https://instagram.com/codinginflow
TikTok: https://tiktok.com/@codinginflow
Facebook: https://facebook.com/codinginflow

Timestamps:
0:00 - Introduction
0:51 - Sample code
2:06 - Mistake 1: Not wrapping client-side server action calls into transitions (useTransition, revalidatePath)
9:27 - Mistake 2: Not validating the user input server-side (Zod)
14:49 - Mistake 3: Not authenticating the user server-side
16:17 - Mistake 4: Not returning errors correctly
21:35 - useActionState
23:40 - Mistake 5: Using server actions to fetch data (GET request)