nextjs-server-action-validation

Validate Next.js Server Action inputs with authentication, Zod schemas, and org-scoped authorization.

1|Updated May 6, 2026
One-click install
npx skills add https://github.com/jacob-balslev/skill-graph --skill nextjs-server-action-validation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nextjs-server-action-validation
Source: https://github.com/jacob-balslev/skill-graph/tree/main/examples/projects/saas-stripe-postgres/skills/nextjs-server-action-validation
Command: npx skills add https://github.com/jacob-balslev/skill-graph --skill nextjs-server-action-validation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents untrusted user input from reaching Next.js Server Actions and databases by enforcing authentication, schema validation, and tenant/org authorization in a safe order.

Core Features & Use Cases

  • Enforces validation order: authenticate first, then validate with Zod, then apply org-scoping checks before any database access.
  • Uses safe parsing and controlled error surfaces: returns structured errors via safeParse to avoid leaking stack traces or query details.
  • Supports secure multi-tenant writes: requires database calls to go through an org-scoped query helper (e.g., orgQuery) after input is validated.

Quick Start

Use the nextjs-server-action-validation skill when implementing a Next.js Server Action endpoint that receives user-submitted form data, and structure it to run getServerSession authentication and Schema.safeParse validation before any database call.

Frequently Asked Questions about nextjs-server-action-validation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate Next.js Server Actions before writing to a database?

To validate Next.js Server Actions, enforce a strict order: authenticate the session first, parse inputs with Zod safeParse, and verify org-scoped authorization before any database access. This prevents untrusted user input from reaching your database writes.

What is the correct order of authentication and Zod validation in Next.js Server Actions?

The correct order for Next.js Server Actions is to run authentication checks first, followed by Zod schema validation via safeParse, and then apply multi-tenant org-scoping checks before executing any database queries or mutations.

How do I securely handle multi-tenant authorization in Next.js Server Actions?

Secure multi-tenant authorization in Next.js Server Actions requires comparing the session orgId against the input orgId after validation. All database writes must route through an orgQuery-based scoping layer to enforce tenant isolation safely.

Does this Next.js Server Action validation approach apply to route handlers and webhooks?

No, this validation approach excludes route handlers, Server Component data fetching, and Stripe webhook handling. It specifically targets mutation workflows where client-submitted form data or action parameters are processed via public POST-style endpoints.

Why use safeParse instead of parse for Zod validation in Server Actions?

Using safeParse for Zod validation in Server Actions returns structured errors gracefully without throwing exceptions. This controlled error surface prevents leaking stack traces or sensitive query details back to the client when invalid data is submitted.

How do I prevent unauthorized database access in Next.js Server Actions?

Prevent unauthorized database access in Next.js Server Actions by authenticating the user session and validating inputs with Zod before calling the database. Route all subsequent writes through an orgQuery helper to enforce strict tenant scoping.