Field error
In this example, we return a server-side field error if the email is already taken.
import { InputError } from 'composable-functions'
const schema = z.object({
email: z.string().min(1).email(),
password: z.string().min(1),
})
const takenEmails = ['[email protected]', '[email protected]']
const mutation = applySchema(schema)(async (values) => {
if (takenEmails.includes(values.email)) {
throw new InputError('Email already taken', ['email'])
}
return values
})
export const action = async ({ request }: Route.ActionArgs) =>
formAction({ request, schema, mutation })
export default () => <SchemaForm schema={schema} />