Server Action Patterns — Auth, Validation, Error Handling
Complete guide to writing production server actions with requireAuth, Zod validation, structured error handling, and revalidation.
Checklist
Auto-generated from the 13 rules this article references — each links to the enforceable rule.
References
Addresses
Rules
Never import server-only code in client componentsScope all mutations to the authenticated organizationNever use any — use unknown for truly unknown typesNever use the admin client for reads in server actionsReturn the supabaseResponse object unchanged from middlewareUse error.tsx for route-level error boundariesUse requireAuth() as the first call in every authenticated server actionUse revalidatePath after server action mutationsValidate all server action inputs at the boundaryValidate and sanitize all user input
Tags
nextjssupabase
More from this skill
Explore more rules and knowledge
BeforeMerge offers hundreds of code review rules, guides, and detection patterns to help your team ship better code.