CAPTCHA support with Cloudflare Turnstile
Cloudflare Turnstile is a friendly, free CAPTCHA replacement, and it works seamlessly with Supabase Edge Functions to protect your forms. View on GitHub.
Setup#
- Follow these steps to set up a new site: https://developers.cloudflare.com/turnstile/get-started/
- Add the Cloudflare Turnstile widget to your site: https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/
Code#
Create a new function in your project:
_10supabase functions new cloudflare-turnstile
And add the code to the index.ts
file:
Deploy the server-side validation Edge Functions#
_10supabase functions deploy cloudflare-turnstile_10supabase secrets set CLOUDFLARE_TURNSTILE_SECRET_KEY=your_secret_key
Invoke the function from your site#
_10const { data, error } = await supabase.functions.invoke('cloudflare-turnstile', {_10 body: { token },_10})