# safe-action-advanced

This skill covers advanced next-safe-action patterns for bound inputs, metadata, framework errors, inferred types, and server callbacks.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 1200 installs · ★ 1
- Author: next-safe-action
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/next-safe-action/skills/tree/HEAD/skills/safe-action-advanced/SKILL.md
- Updated: 2026-09-03
- HTML: https://affpapa.org/en/nevibecode/skills/safe-action-advanced

## What it does

The skill covers extra values passed to actions with `.bind()`, typed metadata for middleware, and the `InferSafeActionFnInput` and `InferSafeActionFnResult` helpers. It also explains how actions can handle `redirect`, `notFound`, `forbidden`, and `unauthorized`.

A separate section describes the callbacks accepted by `.action()`: `onSuccess`, `onError`, `onSettled`, and `onNavigation`. These run on the server, while callbacks supplied to `useAction` belong to the browser. The material also separates `throwServerError` from `returnServerError()`.

Server callbacks run in Node.js, so browser hook behavior should not be assumed for this part of an action.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add next-safe-action/skills --skill safe-action-advanced -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/safe-action-advanced/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/safe-action-advanced/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add next-safe-action/skills --skill safe-action-advanced -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/safe-action-advanced/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add next-safe-action/skills --skill safe-action-advanced -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/safe-action-advanced/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install next-safe-action/skills safe-action-advanced
```

2. **Manually: put the files in place**
- File: `.github/skills/safe-action-advanced/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add next-safe-action/skills --skill safe-action-advanced -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/next-safe-action/skills --path skills/safe-action-advanced
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/safe-action-advanced/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add next-safe-action/skills --skill safe-action-advanced -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/next-safe-action/skills/tree/HEAD/skills/safe-action-advanced/SKILL.md

## When to use it
- pass extra values to an action with `.bind()`
- attach typed metadata for middleware
- handle `redirect`, `notFound`, `forbidden`, and `unauthorized`
- derive types from action functions and middleware
- configure server callbacks for success and failure

## Example prompts
- Show how to pass a `resourceId` into an action with `.bind()` while keeping the types intact.
- Set up `onSuccess`, `onError`, and `onSettled` in the second argument of `.action()`.
- Explain when to use `throwServerError` instead of `returnServerError()` for a handled error.

## Similar
- [nextjs-advanced-routing](https://affpapa.org/en/nevibecode/skills/nextjs-advanced-routing.md) — skill · 334 installs
- [typescript-advanced-types](https://affpapa.org/en/nevibecode/skills/typescript-advanced-types.md) — skill · 92169 installs
- [nextjs-app-router](https://affpapa.org/en/nevibecode/skills/nextjs-app-router.md) — skill · 3900 installs
- [mcp-server-skills](https://affpapa.org/en/nevibecode/skills/mcp-server-skills.md) — skill · 385 installs
- [nextjs-client-cookie-pattern](https://affpapa.org/en/nevibecode/skills/nextjs-client-cookie-pattern.md) — skill · 323 installs
- [typescript-advanced](https://affpapa.org/en/nevibecode/skills/typescript-advanced.md) — skill · 552 installs

From the same set: [next-safe-action/skills](https://affpapa.org/en/nevibecode/by/next-safe-action/skills.md) — 6 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
