createCaptchaAdapter
Build a custom captcha adapter that verifies a challenge token.
createCaptchaAdapter declares a custom captcha adapter, typed against the CaptchaAdapter contract. Kizlo calls it
to verify a challenge token submitted with a request. Register the result on
createKizlo's adapters.captcha.
Reach for this to support a provider Kizlo doesn't ship. For Turnstile, reCAPTCHA, hCaptcha, and friends, use a prebuilt adapter instead. Those live in the adapter guides, not here.
Parameters
createCaptchaAdapter(adapter)adapter
The verify function, (input: { token, ip }) => Promise<boolean>. It receives the user-submitted token and the
caller's ip, verifies the token with your provider, and resolves true for a human, false otherwise.
Returns
The function, unchanged. createCaptchaAdapter only attaches the CaptchaAdapter type so you get inference and one
documented entry point.
Examples
import { createCaptchaAdapter } from "kizlo"
export const captcha = createCaptchaAdapter(async ({ token, ip }) => {
const res = await fetch("https://example.com/siteverify", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({ secret: process.env.CAPTCHA_SECRET!, response: token, remoteip: ip }),
})
const data = await res.json()
return data.success === true
})Register it:
import { createKizlo } from "kizlo"
import { captcha } from "../adapters/captcha"
export const { client, handler } = createKizlo({
adapters: { captcha },
})