Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add Turnstile docs

[email protected]365347bcc785
diff --git a/apps/docs/pages/guides/auth/auth-captcha.mdx b/apps/docs/pages/guides/auth/auth-captcha.mdx
index 6aaee2f4388..5a428c9576a 100644
--- a/apps/docs/pages/guides/auth/auth-captcha.mdx
+++ b/apps/docs/pages/guides/auth/auth-captcha.mdx
@@ -1,4 +1,5 @@
import Layout from '~/layouts/DefaultGuideLayout'
+import { Accordion } from 'ui'
export const meta = {
id: 'auth-captcha',
@@ -7,7 +8,7 @@ export const meta = {
video: 'https://www.youtube.com/v/em1cpOAXknM',
}
-Supabase provides you with the option of adding captcha to your sign-in, sign-up, and password reset forms. This keeps your website safe from bots and malicious scripts. Supabase authentication has support for [hCaptcha](https://www.hcaptcha.com/).
+Supabase provides you with the option of adding captcha to your sign-in, sign-up, and password reset forms. This keeps your website safe from bots and malicious scripts. Supabase authentication has support for [hCaptcha](https://www.hcaptcha.com/) and [Cloudflare Turnstile](https://www.cloudflare.com/products/turnstile/).
<div className="video-container">
<iframe
@@ -18,7 +19,21 @@ Supabase provides you with the option of adding captcha to your sign-in, sign-up
></iframe>
</div>
-## Sign up for hCaptcha
+## Sign up for Captcha
+
+<Accordion
+ type="default"
+ openBehaviour="multiple"
+ chevronAlign="right"
+ justified
+ size="medium"
+ className="text-scale-900 dark:text-white"
+ >
+ <div className="border-b pb-3">
+ <Accordion.Item
+ header={<span className="text-scale-1200 font-bold">HCaptcha</span>}
+ id={`HCaptcha-Signup`}
+ >
Go to the [hCaptcha](https://www.hcaptcha.com/) website and sign up for an account. On the welcome page, copy the **Sitekey** and **Secret key**.
@@ -33,18 +48,46 @@ The **Sitekey** can be found in the **Settings** of the active site you created.
In the Settings page, look for the **Sitekey** section and copy the key.
![sitekey_settings.png](/docs/img/guides/auth-captcha/sitekey_settings.png)
+ </Accordion.Item>
-## Enable hCaptcha protection for your Supabase project
+ </div>
+ <div className="border-b pb-3">
+ <Accordion.Item
+ header={<span className="text-scale-1200 font-bold">Turnstile</span>}
+ id={`Turnstile-Signup`}
+ >
+ Go to the [Cloudflare website](https://dash.cloudflare.com/login) and sign up for an account. On the welcome page, head to the Turnstile section and add a new site. Create a site and take note of the **Sitekey** and **Secret Key** as shown below
+ ![cloudflare_settings.png](/docs/img/guides/auth-captcha/cloudflare_settings.png)
-Navigate to the **[Authentication](https://app.supabase.com/project/_/settings/auth)** page in the Supabase Dashboard and find the **Enable hCaptcha protection** toggle under the **Security and Protection** section.
+ </Accordion.Item>
+ </div>
+ </Accordion>
+
+## Enable Captcha protection for your Supabase project
+
+Navigate to the **[Authentication](https://app.supabase.com/project/_/settings/auth)** page in the Supabase Dashboard and find the **Enable Captcha protection** toggle under the **Security and Protection** section.
![supabase_auth_general_settings.png](/docs/img/guides/auth-captcha/supabase_auth_general_settings.png)
-Enter your hCaptcha **Secret key** and click **Save**.
+Enter your Captcha **Secret key** and click **Save**.
-## Add the hCaptcha frontend component
+## Add the Captcha frontend component
-The frontend requires some changes to provide the captcha on-screen for the user. This example uses React and the hCaptcha React component, but hCaptcha can be used with any JavaScript framework.
+The frontend requires some changes to provide the captcha on-screen for the user. This example uses React and the corresponding Captcha React component, but both Captcha providers can be used with any JavaScript framework.
+
+<Accordion
+ type="default"
+ openBehaviour="multiple"
+ chevronAlign="right"
+ justified
+ size="medium"
+ className="text-scale-900 dark:text-white"
+ >
+ <div className="border-b pb-3">
+ <Accordion.Item
+ header={<span className="text-scale-1200 font-bold">HCaptcha</span>}
+ id={`HCaptcha-React`}
+ >
Install `@hcaptcha/react-hcaptcha` in your project as a dependency.
@@ -116,7 +159,54 @@ captcha.current.resetCaptcha()
```
In order to test that this works locally we will need to use something like [ngrok](https://ngrok.com/) or add an entry to your hosts file. You can read more about this in the [hCaptcha docs](https://docs.hcaptcha.com/#local-development).
+ </Accordion.Item>
+ </div>
+<div className="border-b pb-3">
+ <Accordion.Item
+ header={<span className="text-scale-1200 font-bold">Turnstile</span>}
+ id={`Turnstile-React`}
+ >
+ The frontend requires some changes to provide the captcha on-screen for the user. This example uses React and the Turnstile React component, but Turnstile can be used with any JavaScript framework.
+Install @marsidev/react-turnstile in your project as a dependency.
+
+```bash
+npm install @marsidev/react-turnstile
+```
+
+
+Now import the Turnstile component from the @marsidev/react-turnstile library.
+
+```jsx
+import { Turnstile } from '@marsidev/react-turnstile'
+```
+
+
+Let’s create a empty state to store our `captchaToken`
+
+```jsx
+const [captchaToken, setCaptchaToken] = useState()
+```
+
+Now lets add the Cloudflare Turnstile component to the JSX section of our code
+
+```html
+<Turnstile />
+```
+
+We will pass it the sitekey we copied from the Cloudflare website as a property along with a onVerify property which takes a callback function. This callback function will have a token as one of its properties. Let's set the token in the state using `setCaptchaToken`
+
+```jsx
+<Turnstile
+ sitekey="your-sitekey"
+  onVerify={(token) => { setCaptchaToken(token) }
+/>
+```
+
+To test locally, you will need to add localhost to the domain whitelist as per the [Cloudflare docs](https://developers.cloudflare.com/turnstile/reference/testing/)
+ </Accordion.Item>
+ </div>
+ </Accordion>
Run the application and you should now be provided with a captcha challenge.
export const Page = ({ children }) => <Layout meta={meta} children={children} />
diff --git a/apps/docs/public/img/guides/auth-captcha/cloudflare_settings.png b/apps/docs/public/img/guides/auth-captcha/cloudflare_settings.png
new file mode 100644
index 00000000000..d3387436240
Binary files /dev/null and b/apps/docs/public/img/guides/auth-captcha/cloudflare_settings.png differ