From 5b324abc7cd2aa4f5ccc6973bd477c53ceae75c8 Mon Sep 17 00:00:00 2001 From: Bently Date: Thu, 5 Jun 2025 14:06:29 +0100 Subject: [PATCH] update(turnstile): Add env to hide turnstile for dev deploy (#10116) This simply adds a env to hide turnstile for dev deploys if this env ``NEXT_PUBLIC_DISABLE_TURNSTILE`` is set to false which it is by default, it will show turnstile, if the env is set to "true" it will hide the turnstile #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Login/register with ``NEXT_PUBLIC_DISABLE_TURNSTILE=false`` and you see the turnstile and that is needed to login/signup - [x] Login/register with ``NEXT_PUBLIC_DISABLE_TURNSTILE=true`` and you will see the turnstile is gone, and you can login/signup with out it --- autogpt_platform/frontend/.env.example | 1 + autogpt_platform/frontend/src/hooks/useTurnstile.ts | 7 +++++-- autogpt_platform/frontend/src/lib/turnstile.ts | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/autogpt_platform/frontend/.env.example b/autogpt_platform/frontend/.env.example index 0eb8872371..675d0ab1fc 100644 --- a/autogpt_platform/frontend/.env.example +++ b/autogpt_platform/frontend/.env.example @@ -30,3 +30,4 @@ NEXT_PUBLIC_SHOW_BILLING_PAGE=false ## Get these from the Cloudflare Turnstile dashboard: https://dash.cloudflare.com/?to=/:account/turnstile ## This is the frontend site key NEXT_PUBLIC_CLOUDFLARE_TURNSTILE_SITE_KEY= +NEXT_PUBLIC_DISABLE_TURNSTILE=false diff --git a/autogpt_platform/frontend/src/hooks/useTurnstile.ts b/autogpt_platform/frontend/src/hooks/useTurnstile.ts index edb7e9b6fa..18bbb06c62 100644 --- a/autogpt_platform/frontend/src/hooks/useTurnstile.ts +++ b/autogpt_platform/frontend/src/hooks/useTurnstile.ts @@ -47,10 +47,13 @@ export function useTurnstile({ useEffect(() => { const behaveAs = getBehaveAs(); const hasTurnstileKey = !!TURNSTILE_SITE_KEY; + const turnstileDisabled = process.env.NEXT_PUBLIC_DISABLE_TURNSTILE === "true"; - setShouldRender(behaveAs === BehaveAs.CLOUD && hasTurnstileKey); + // Only render Turnstile in cloud environment if not explicitly disabled + setShouldRender(behaveAs === BehaveAs.CLOUD && hasTurnstileKey && !turnstileDisabled); - if (behaveAs !== BehaveAs.CLOUD || !hasTurnstileKey) { + // Skip verification if disabled, in local development, or no key + if (turnstileDisabled || behaveAs !== BehaveAs.CLOUD || !hasTurnstileKey) { setVerified(true); } }, []); diff --git a/autogpt_platform/frontend/src/lib/turnstile.ts b/autogpt_platform/frontend/src/lib/turnstile.ts index 0301df7d9b..47194ae627 100644 --- a/autogpt_platform/frontend/src/lib/turnstile.ts +++ b/autogpt_platform/frontend/src/lib/turnstile.ts @@ -7,6 +7,11 @@ export async function verifyTurnstileToken( token: string, action?: string, ): Promise { + // Skip verification if explicitly disabled via environment variable + if (process.env.NEXT_PUBLIC_DISABLE_TURNSTILE === "true") { + return true; + } + // Skip verification in local development const behaveAs = getBehaveAs(); if (behaveAs !== BehaveAs.CLOUD) {