Skip to content
Discussion options

You must be logged in to vote

inputValidator does not have to be Zod-specific. The function just needs to take the incoming data and return the validated/transformed data, or throw if the input is invalid.

With a custom validator, the shape is roughly:

const createThing = createServerFn({ method: "POST" })
  .inputValidator((input: unknown) => {
    const result = myValidator(input)

    if (!result.ok) {
      throw new Error(result.message)
    }

    return result.value
  })
  .handler(async ({ data }) => {
    // data is the value returned by inputValidator
  })

If your validation library returns structured errors, wrap those in your own error type, or throw a response/error shape your app knows how to display.

Th…

Replies: 1 comment

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants