Type-safe Server Actions for Next.js

Type-safe, validated and middleware-powered Server Actions for Next.js. Supports any validator that implements the Standard Schema specification.

action.ts
"use server";
const action = actionClient
.use(authMiddleware)
.inputSchema(z.object({
name: z.string().min(1),
}))
.action(async ({ ctx, parsedInput }) => {
return { greeting: `Hello, ${parsedInput.name}!` };
});

What developers are saying

Join thousands of developers who are already using next-safe-action in their projects

Pontus Abrahamsson

Pontus Abrahamsson

@pontusab

If you're using @nextjs server actions, I highly recommend next-safe-action library from @TheEdoRan. In this example, we have: @supabase client in context, Auth middleware, Analytics middleware to OpenPanel, Support for optimistic updates

Jul 15, 2024

Dave Gray

Dave Gray

@yesdavidgray

My Next.js 15 Project series rolls on with Chapter 8! In this video, I show how next-safe-action (@TheEdoRan) and Sentry (@getsentry) are the perfect combo for server actions

Dec 4, 2024

Liam Murray

Liam Murray

@Lermatroid

This is my monthly "try next-safe-action" post. It will blow your mind how easy it is to setup a e2e typesafe api in next.

Sep 19, 2024

Kingsley O.

Kingsley O.

@Kingsley_codes

If you aren't using next-safe-actions by @TheEdoRan for your Next 14 app, what are you waiting for? The DX is marvelous. An even better package than zact and @t3dotgg recommends it too so you know it's good!

Oct 28, 2023

Nik Elsnik

Nik Elsnik

@nikelsnik

My go-to method for handling forms in @nextjs: react-hook-form for form handling, zod for validation, shadcn/ui for UI components, next-safe-action for server actions, sonner for toast messages

Sep 11, 2024

Antonio

Antonio

@zaphodias

step 1: upgrade to next 13.4; step 2: understand actions; step 3: use @TheEdoRan's lib

May 4, 2023

rigo

rigo

@rclmenezes

I predict that next-safe-action is going to get a loooooot of stars in a few hours :) Props @TheEdoRan

May 4, 2023

Erfan Ebrahimnia

Erfan Ebrahimnia

@ErfanEbrahimnia

Using next-safe-action by @TheEdoRan in a project right now and really like it. It handles input-validation and errors when using Server Actions

Sep 7, 2023

Yiwei Ho

Yiwei Ho

@1weiho

Recently, my favorite package to use with Next.js is next-safe-action, which allows you to wrap all server actions with a custom action client that can define effects similar to middleware for server actions using a pipeline pattern, such as authentication and rate limiting.

Dec 21, 2024

Pontus Abrahamsson

Pontus Abrahamsson

@pontusab

If you're using @nextjs server actions, I highly recommend next-safe-action library from @TheEdoRan. In this example, we have: @supabase client in context, Auth middleware, Analytics middleware to OpenPanel, Support for optimistic updates

Jul 15, 2024

Dave Gray

Dave Gray

@yesdavidgray

My Next.js 15 Project series rolls on with Chapter 8! In this video, I show how next-safe-action (@TheEdoRan) and Sentry (@getsentry) are the perfect combo for server actions

Dec 4, 2024

Liam Murray

Liam Murray

@Lermatroid

This is my monthly "try next-safe-action" post. It will blow your mind how easy it is to setup a e2e typesafe api in next.

Sep 19, 2024

Kingsley O.

Kingsley O.

@Kingsley_codes

If you aren't using next-safe-actions by @TheEdoRan for your Next 14 app, what are you waiting for? The DX is marvelous. An even better package than zact and @t3dotgg recommends it too so you know it's good!

Oct 28, 2023

Nik Elsnik

Nik Elsnik

@nikelsnik

My go-to method for handling forms in @nextjs: react-hook-form for form handling, zod for validation, shadcn/ui for UI components, next-safe-action for server actions, sonner for toast messages

Sep 11, 2024

Antonio

Antonio

@zaphodias

step 1: upgrade to next 13.4; step 2: understand actions; step 3: use @TheEdoRan's lib

May 4, 2023

rigo

rigo

@rclmenezes

I predict that next-safe-action is going to get a loooooot of stars in a few hours :) Props @TheEdoRan

May 4, 2023

Erfan Ebrahimnia

Erfan Ebrahimnia

@ErfanEbrahimnia

Using next-safe-action by @TheEdoRan in a project right now and really like it. It handles input-validation and errors when using Server Actions

Sep 7, 2023

Yiwei Ho

Yiwei Ho

@1weiho

Recently, my favorite package to use with Next.js is next-safe-action, which allows you to wrap all server actions with a custom action client that can define effects similar to middleware for server actions using a pipeline pattern, such as authentication and rate limiting.

Dec 21, 2024

Pontus Abrahamsson

Pontus Abrahamsson

@pontusab

The best way to handle forms in @nextjs, from client to database: Shadcn for UI components, React Hook Form for form handling, zod for validation, next-safe-action for server actions

Aug 15, 2024

Xexr

Xexr

@Xexr

@t3dotgg I saw you mention next-safe-action on your live stream. I wanted to throw my hat in the ring and give it a shout out. It's honestly great, @TheEdoRan has done a fantastic job and it deserves way more attention.

Jun 28, 2023

Caster

Caster

@CasterKno

I recently came across a library called next-safe-action, which I'm impressed with. I'll definitely be using it in my next project.

Jun 23, 2024

Murat Sutunc

Murat Sutunc

@muratsutunc

next-safe-action is highly recommended

Dec 15, 2024

Rajdeep

Rajdeep

@Rajdeep__ds

Just tried @TheEdoRan's next-safe-action with @nextjs 15 Server Actions—it's a game-changer! 🚀 Type-safe server actions + seamless DX = 🔥 Highly recommend checking it out! 🤩

Jan 1, 2025

Justin

Justin

@JustinLicata

Using next-safe-action for Next.js server actions has been a game changer for us. It makes type safety solid, error handling clearer and everything just feels more consistent and reliable for an improved DX.

Jan 8, 2026

Dmytro Krasun

Dmytro Krasun

@DmytroKrasun

You don't need tRPC with Next.js. You need type safe Server Actions 👉 https://next-safe-action.dev

Dec 24, 2025

Gus

Gus

@guscsales

next-safe-action handles the messy parts so you don't have to. Simple, safe, and actually pleasant to use.

Dec 23, 2025

Pontus Abrahamsson

Pontus Abrahamsson

@pontusab

The best way to handle forms in @nextjs, from client to database: Shadcn for UI components, React Hook Form for form handling, zod for validation, next-safe-action for server actions

Aug 15, 2024

Xexr

Xexr

@Xexr

@t3dotgg I saw you mention next-safe-action on your live stream. I wanted to throw my hat in the ring and give it a shout out. It's honestly great, @TheEdoRan has done a fantastic job and it deserves way more attention.

Jun 28, 2023

Caster

Caster

@CasterKno

I recently came across a library called next-safe-action, which I'm impressed with. I'll definitely be using it in my next project.

Jun 23, 2024

Murat Sutunc

Murat Sutunc

@muratsutunc

next-safe-action is highly recommended

Dec 15, 2024

Rajdeep

Rajdeep

@Rajdeep__ds

Just tried @TheEdoRan's next-safe-action with @nextjs 15 Server Actions—it's a game-changer! 🚀 Type-safe server actions + seamless DX = 🔥 Highly recommend checking it out! 🤩

Jan 1, 2025

Justin

Justin

@JustinLicata

Using next-safe-action for Next.js server actions has been a game changer for us. It makes type safety solid, error handling clearer and everything just feels more consistent and reliable for an improved DX.

Jan 8, 2026

Dmytro Krasun

Dmytro Krasun

@DmytroKrasun

You don't need tRPC with Next.js. You need type safe Server Actions 👉 https://next-safe-action.dev

Dec 24, 2025

Gus

Gus

@guscsales

next-safe-action handles the messy parts so you don't have to. Simple, safe, and actually pleasant to use.

Dec 23, 2025

Everything you need for safe server actions

End-to-End Type Safety

Full TypeScript inference from schema definition to React hooks. No manual type wiring needed.

Standard Schema support

Standard Schema v1 support: Zod, Valibot, ArkType, Yup, and any compliant validator.

Chainable Middleware

Composable .use() middleware with typed context propagation across the entire chain.

React Hooks

useAction and useOptimisticAction hooks with rich status tracking and callbacks.

Smart Error Handling

Validation, server, and Next.js navigation errors handled gracefully with typed results.

Optimistic Updates

Built-in optimistic UI support with automatic rollback on server action failure.

How it works

safe-action.ts
import { createSafeActionClient } from "next-safe-action";
 
export const actionClient = createSafeActionClient();

Get started in seconds

$ npm i next-safe-action