diff --git a/website/docs/define-actions/action-utils.md b/website/docs/define-actions/action-utils.md index 6628923..da08ab7 100644 --- a/website/docs/define-actions/action-utils.md +++ b/website/docs/define-actions/action-utils.md @@ -18,7 +18,7 @@ Starting from v7.4.0, you can now pass optional `throwServerError` and `throwVal - `onError`: called when action execution fails (validation errors or server error). - `onSettled`: called when action execution succeeds or fails. -With action callbacks you can perform custom logic after the action is executed, on the server side. You can pass them to [`action`/`stateAction`](/docs/define-actions/instance-methods#action--stateaction) method in the second argument, after the server code function. They don't return anything and can be async or not. +With action callbacks you can perform custom logic after the action is executed, on the server side. You can pass them to [`action`/`stateAction`](/docs/define-actions/instance-methods#action--stateaction) method as the second argument, after the server code function. Their return value is not used and they **must** be async functions. ```tsx import { actionClient } from "@/lib/safe-action"; @@ -29,7 +29,7 @@ const action = actionClient .action(async () => { // ... }, { - onSuccess: ({ + onSuccess: async ({ data, ctx, metadata, @@ -39,22 +39,24 @@ const action = actionClient bindArgsParsedInputs, hasRedirected, hasNotFound, + hasForbidden }) => {}, - onError: ({ + onError: async ({ error, ctx, metadata, clientInput, bindArgsClientInputs }) => {}, - onSettled: ({ + onSettled: async ({ result, ctx, metadata, clientInput, bindArgsClientInputs, hasRedirected, - hasNotFound + hasNotFound, + hasForbidden }) => {}, }); ``` \ No newline at end of file diff --git a/website/docs/define-actions/instance-methods.md b/website/docs/define-actions/instance-methods.md index 9be92ec..3d48e87 100644 --- a/website/docs/define-actions/instance-methods.md +++ b/website/docs/define-actions/instance-methods.md @@ -31,7 +31,7 @@ metadata(data: Metadata) => new SafeActionClient() schema(inputSchema: S, utils?: { handleValidationErrorsShape?: HandleValidationErrorsShapeFn } }) => new SafeActionClient() ``` -`schema` accepts an input schema of type `Schema` or a function that returns a promise of type `Schema` and an optional `utils` object that accepts a [`handleValidationErrorsShape`](/docs/define-actions/validation-errors#customize-validation-errors-format) function. The schema is used to define the arguments that the safe action will receive, the optional [`handleValidationErrorsShape`](/docs/define-actions/validation-errors#customize-validation-errors-format) function is used to return a custom format for validation errors. If you don't pass an input schema, `parsedInput` and validation errors will be typed `undefined`, and `clientInput` will be typed `void`. It returns a new instance of the safe action client. +`schema` accepts an input schema of type `Schema` or a function that returns a promise of type `Schema` and an optional `utils` object that accepts an async [`handleValidationErrorsShape`](/docs/define-actions/validation-errors#customize-validation-errors-format) function. The schema is used to define the arguments that the safe action will receive, the optional [`handleValidationErrorsShape`](/docs/define-actions/validation-errors#customize-validation-errors-format) function is used to return a custom format for validation errors. If you don't pass an input schema, `parsedInput` and validation errors will be typed `undefined`, and `clientInput` will be typed `void`. It returns a new instance of the safe action client. ### `bindArgsSchemas` @@ -39,7 +39,7 @@ schema(inputSchema: S, utils?: { handleValidationErrorsShape?: HandleValidationE bindArgsSchemas(bindArgsSchemas: BAS, bindArgsUtils?: { handleBindArgsValidationErrorsShape?: HandleBindArgsValidationErrorsShapeFn }) => new SafeActionClient() ``` -`bindArgsSchemas` accepts an array of bind input schemas of type `Schema[]` and an optional `bindArgsUtils` object that accepts a `handleBindArgsValidationErrorsShape` function. The schema is used to define the bind arguments that the safe action will receive, the optional `handleBindArgsValidationErrorsShape` function is used to [return a custom format for bind arguments validation errors](/docs/define-actions/validation-errors#customize-validation-errors-format). It returns a new instance of the safe action client. +`bindArgsSchemas` accepts an array of bind input schemas of type `Schema[]` and an optional `bindArgsUtils` object that accepts an async [`handleBindArgsValidationErrorsShape`](/docs/define-actions/validation-errors#customize-validation-errors-format) function. The schema is used to define the bind arguments that the safe action will receive, the optional [`handleBindArgsValidationErrorsShape`](/docs/define-actions/validation-errors#customize-validation-errors-format) function is used to [return a custom format for bind arguments validation errors](/docs/define-actions/validation-errors#customize-validation-errors-format). It returns a new instance of the safe action client. ### `outputSchema` diff --git a/website/docs/define-actions/validation-errors.md b/website/docs/define-actions/validation-errors.md index 2b9a50c..1ad0749 100644 --- a/website/docs/define-actions/validation-errors.md +++ b/website/docs/define-actions/validation-errors.md @@ -11,7 +11,7 @@ next-safe-action, by default, emulates Zod's [`format`](https://zod.dev/ERROR_HA This can be customized both at the safe action client level and at the action level by: - using [`defaultValidationErrorsShape`](/docs/define-actions/create-the-client#defaultvalidationerrorsshape) optional property in `createSafeActionClient`; -- using `handleValidationErrorsShape` and `handleBindArgsValidationErrorsShape` optional functions in [`schema`](/docs/define-actions/instance-methods#schema) and [`bindArgsSchemas`](/docs/define-actions/instance-methods#bindargsschemas) methods. +- using `handleValidationErrorsShape` and `handleBindArgsValidationErrorsShape` optional async functions in [`schema`](/docs/define-actions/instance-methods#schema) and [`bindArgsSchemas`](/docs/define-actions/instance-methods#bindargsschemas) methods. The second way overrides the shape set at the instance level, per action. @@ -39,13 +39,13 @@ export const loginUser = actionClient // Here we use the `flattenValidationErrors` function to customize the returned validation errors // object to the client. // highlight-next-line - handleValidationErrorsShape: (ve, utils) => flattenValidationErrors(ve).fieldErrors, + handleValidationErrorsShape: async (ve, utils) => flattenValidationErrors(ve).fieldErrors, }) .bindArgsSchemas(bindArgsSchemas, { // Here we use the `flattenBindArgsValidatonErrors` function to customize the returned bind args // validation errors object array to the client. // highlight-next-line - handleBindArgsValidationErrorsShape: (ve, utils) => flattenBindArgsValidationErrors(ve), + handleBindArgsValidationErrorsShape: async (ve, utils) => flattenBindArgsValidationErrors(ve), }) .action(async ({ parsedInput: { username, password } }) => { // Your code here... diff --git a/website/docs/getting-started.mdx b/website/docs/getting-started.mdx index cb48639..68383ff 100644 --- a/website/docs/getting-started.mdx +++ b/website/docs/getting-started.mdx @@ -16,6 +16,10 @@ import TabItem from '@theme/TabItem'; - A supported validation library: Zod, Valibot, Yup, TypeBox ::: +:::warning +Next.js >= 15.0.5 is required for using next-safe-action >= 7.9.10. This is due to internal error handling framework changes. So, please upgrade to the latest version to use this library with Next.js 15.0.5 or later. +::: + **next-safe-action** provides a typesafe Server Actions implementation for Next.js App Router applications. ## Installation