Skip to content

nuxt-actionsType-Safe Server Actions for Nuxt

Validated inputs, middleware chains, builder pattern, and optimistic updates. Works with Zod, Valibot, and ArkType through Standard Schema.

nuxt-actions

Quick Example

Define a validated server action:

ts
// server/api/todos.post.ts
import { z } from 'zod'

export default defineAction({
  input: z.object({
    title: z.string().min(1, 'Title is required'),
  }),
  handler: async ({ input }) => {
    return await db.todo.create({ data: { title: input.title } })
  },
})

Call it from any component:

vue
<script setup lang="ts">
const { execute, data, error, status } = useAction<
  { title: string },
  { id: number; title: string }
>('/api/todos')

async function addTodo() {
  await execute({ title: 'Buy milk' })
}
</script>

<template>
  <button @click="addTodo" :disabled="status === 'executing'">
    Add Todo
  </button>
  <p v-if="data">Created: {{ data.title }}</p>
  <p v-if="error" class="error">{{ error.message }}</p>
</template>

You get validated input, typed handler parameters, reactive state management, and a consistent error format -- with zero configuration.

Released under the MIT License.