v0.8.1 — Secure defaults, typed client errors & merged optimistic updates

Type-safe Server Actions
for Nuxt

Validate contracts on the server with your preferred schema library. Build forms and mutations with typed middleware, predictable field errors, cancellation, and optimistic updates.

Define on the server. Use on the client. Types flow automatically.

server/actions/create-post.tsServer
import { z } from 'zod'
import { actionClient } from '../utils/action-client'

export default actionClient
  .schema(z.object({
    title: z.string().trim().min(1).max(200),
  }))
  .outputSchema(z.object({
    id: z.string(), title: z.string(),
  }))
  .action(({ parsedInput }) => ({
    id: crypto.randomUUID(),
    title: parsedInput.title,
  }))
// Demo response; connect your persistence.
Full type inference
components/CreatePost.vueClient
<script setup lang="ts">
import { createPost } from '#safe-action/actions'

const { values, submit, data, fieldErrors, isExecuting } =
  useFormAction(createPost, {
    initialValues: { title: '' },
  })
</script>

<template>
  <form @submit.prevent="submit()">
    <input v-model="values.title" aria-label="Title" />
    <p v-for="message in fieldErrors.title" :key="message">
      {{ message }}
    </p>
    <button :disabled="isExecuting">Create</button>
    <p v-if="data">Created: {{ data.title }}</p>
  </form>
</template>
server/actions/create-post.ts
import { z } from 'zod'
import { actionClient } from '../utils/action-client'

export default actionClient
  .schema(z.object({
    title: z.string().trim().min(1).max(200),
  }))
  .outputSchema(z.object({
    id: z.string(), title: z.string(),
  }))
  .action(({ parsedInput }) => ({
    id: crypto.randomUUID(),
    title: parsedInput.title,
  }))
// Demo response; connect your persistence.

Validated contracts, predictable forms, and explicit request behavior.

End-to-end Type Safety

Input and output types flow from server to client automatically. No manual type definitions needed.

Standard Schema Validation

Use Zod, Valibot, ArkType, Yup, or another Standard Schema validator. Input and parsed-output types follow the declared schema contracts.

Composable Middleware

Chain auth checks, logging, rate limiting, and more with fully typed context passing.

Typed Forms & Optimistic Updates

Track nested field state, validate snapshots, handle typed business failures, and refresh matching Nuxt queries after successful mutations.

Auto Route Generation

Drop files in server/actions/ and API routes are created for you. Zero configuration.

Explicit Request Lifecycle

Latest execution owns state. Configure cancellation, timeouts, headers, and optional scope disposal explicitly.

Ready to get started?

Add nuxt-safe-action to your project in seconds.

Copyright © 2026