safe-action-client

Configure next-safe-action clients with validated server actions and structured error handling.

Updated Jul 8, 2026
One-click install
npx skills add https://github.com/NarixHine/uni-chem --skill safe-action-client-narixhine
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: safe-action-client
Source: https://github.com/NarixHine/uni-chem/tree/main/.agents/skills/safe-action-client
Command: npx skills add https://github.com/NarixHine/uni-chem --skill safe-action-client-narixhine

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires next-safe-action, zod, valibot.

What problem does it solve? Building type-safe Next.js server actions requires repetitive boilerplate for input validation, error handling, and middleware chaining. This Skill provides the patterns and API reference for creating next-safe-action clients that validate inputs and outputs, handle server errors consistently, and compose middleware for authentication and authorization. ## Core Features & Use Cases - Client Configuration: Set up createSafeActionClient with metadata schemas, custom server error handlers, and validation error shapes. - Validated Actions: Define actions with Standard Schema (Zod, Valibot, Yup) input/output validation, bind args, and async schema factories. - Layered Middleware: Build auth and admin clients by chaining .use() middleware that injects typed context like userId and roles. - Use Case: You need an admin-only action that deletes a user. Create an adminActionClient extending an auth client, add a Zod input schema for the target user ID, and return structured validation errors when the email or ID is invalid. ## Quick Start Create a safe action client with Zod input validation and an authentication middleware layer for my Next.js server actions.

Frequently Asked Questions about safe-action-client

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

FAQPage Schema
How do I create a type-safe server action with next-safe-action?▼

Create a client with createSafeActionClient, then chain .inputSchema() with a Zod or Valibot schema before .action(). The server function receives parsedInput typed from your schema, and the action file must include the "use server" directive.

How to add authentication middleware to next-safe-action?▼

Call .use() on a base client with an async middleware that checks the session and throws if unauthenticated. Pass context via next({ ctx: { userId } }) so downstream actions access typed ctx values like userId and userRole.

Does next-safe-action support validation libraries other than Zod?▼

Yes, next-safe-action works with any library implementing the Standard Schema v1 specification, including Valibot, Yup, and ArkType. No adapters are needed; pass the schema directly to .inputSchema() or .outputSchema().

Why is my next-safe-action server action not working?▼

The most common cause is a missing "use server" directive at the top of the action file. Also verify that .metadata() is called before .action() when defineMetadataSchema is configured, since omitting it produces a TypeScript error.

How do I return field-level validation errors from a server action?▼

Use returnValidationErrors from next-safe-action inside your action, passing the schema and an error object with field paths. This produces standardized result.validationErrors on the client instead of returning ad-hoc error objects.