Check out our talk at Remix Conf!

Field error

In this example, we return a server-side field error if the email is already taken.

import { InputError } from 'domain-functions'

const schema = z.object({
  email: z.string().min(1).email(),
  password: z.string().min(1),
})

const takenEmails = ['foo@bar.com', 'bar@foo.com']

const mutation = makeDomainFunction(schema)(async (values) => {
  if (takenEmails.includes(values.email)) {
    throw new InputError('Email already taken', 'email')
  }

  return values
})

export const action: ActionFunction = async ({ request }) =>
  formAction({ request, schema, mutation })

export default () => <Form schema={schema} />