In this example, we use Composable Function's context to authorize a specific header.
const schema = z.object({ email: z.string().min(1).email() })
const contextSchema = z.object({
customHeader: z.string({
error: (issue) =>
issue.input == null
? 'Missing custom header'
: 'Invalid custom header',
}),
})
const mutation = applySchema(
schema,
contextSchema,
)(async (values) => values)
export const action = async ({ request }: Route.ActionArgs) => {
return formAction({
request,
schema,
mutation,
context: { customHeader: request.headers.get('customHeader') },
})
}
export default () => <SchemaForm schema={schema} />