i18n
If you're using a i18n solution, there's a high probability that you'll need to await the translations and then pass them to schemas.
next-safe-action allows you to do that by passing an async function to the schema
method that returns a promise with the schema.
The setup is pretty simple:
"use server";
import { actionClient } from "@/lib/safe-action";
import { z } from "zod";
import { getTranslations } from "my-i18n-lib";
async function getSchema() {
// This is an example of a i18n setup.
const t = await getTranslations();
return mySchema(t); // this is the schema that will be used to validate and parse the input
}
export const myAction = actionClient.schema(getSchema).action(async ({ parsedInput }) => {
// Do something useful here...
});