Check out our talk at Remix Conf!

Environment

In this example, we use Remix Domain's environment to authorize a specific header.

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

const environmentSchema = z.object({
  customHeader: z.string({ invalid_type_error: 'Missing custom header' }),
})

const mutation = makeDomainFunction(
  schema,
  environmentSchema,
)(async (values) => values)

export const action: ActionFunction = async ({ request }) => {
  return formAction({
    request,
    schema,
    mutation,
    environment: { customHeader: request.headers.get('customHeader') },
  })
}

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