Skip to main content

safe-action-advanced

Use when working with bind arguments, metadata schemas, framework errors (redirect/notFound/forbidden/unauthorized), type inference utilities (InferSafeActionFnInput/Result), or server-level action callbacks

소스 정보

저장소
imbhargav5/nextbase-nextjs-supabase-starter
최근 소스 활동
2026년 9월 1일 00:20
감지된 SKILL.md 언어
영어
스타
827
포크
215

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

파일 탐색기
5 개 파일

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
safe-action-advanced
description
Use when working with bind arguments, metadata schemas, framework errors (redirect/notFound/forbidden/unauthorized), type inference utilities (InferSafeActionFnInput/Result), or server-level action callbacks
# next-safe-action Advanced Features ## Overview | Feature | Use Case | |---|---| | [Bind arguments](./bind-arguments.md) | Pass extra args to actions via `.bind()` (e.g., resource IDs) | | [Metadata](./metadata.md) | Attach typed metadata to actions for use in middleware | | [Framework errors](./framework-errors.md) | Handle redirect, notFound, forbidden, unauthorized in actions | | [Type utilities](./type-utilities.md) | Infer types from action functions and middleware | ## Server-Level Action Callbacks The second argument to `.action()` accepts callbacks that run **on the server** (not client-side hooks): ```ts export const createPost = authActionClient .inputSchema(schema) .action( async ({ parsedInput, ctx }) => { const post = await db.post.create(parsedInput); return post; }, { onSuccess: async ({ data, parsedInput, ctx, metadata, clientInput }) => { // Runs on the server after successful execution await invalidateCache("posts"); }, onError: async ({ error, metadata, ctx, clientInput, bindArgsClientInputs }) => { // error: { serverError?, validationErrors? } await logError(error); }, onSettled: async ({ result }) => { // Always runs await recordMetrics(result); }, onNavigation: async ({ navigationKind }) => { // Runs when a framework error (redirect, notFound, etc.) occurs console.log("Navigation:", navigationKind); }, } ); ``` These are distinct from hook callbacks (`useAction({ onSuccess })`) — server callbacks run in the Node.js runtime, hook callbacks run in the browser. ## throwServerError Re-throw server errors instead of returning them as `result.serverError`: ```ts export const myAction = actionClient .inputSchema(schema) .action(serverCodeFn, { throwServerError: true, // The handled server error (return of handleServerError) is thrown }); ``` Don't confuse this with `returnServerError()`: `throwServerError` throws the *handled* error (post-`handleServerError`) instead of returning it, while `returnServerError(payload)` returns a typed *expected* error in `result.serverError`, bypassing `handleServerError` entirely (see the safe-action-client skill's error-handling doc).
GitHub에서 보기