AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend): fix captcha reset
Lluis Agustiaa27365e7fe7
diff --git a/autogpt_platform/frontend/src/app/(platform)/login/page.tsx b/autogpt_platform/frontend/src/app/(platform)/login/page.tsxindex 7a574ccf85..8dad32348b 100644--- a/autogpt_platform/frontend/src/app/(platform)/login/page.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/login/page.tsx@@ -17,6 +17,7 @@ export default function LoginPage() {const {form,feedback,+ captchaToken,isLoading,isLoggedIn,isCloudEnv,@@ -89,6 +90,7 @@ export default function LoginPage() {<Turnstile2onVerified={handleCaptchaVerify}onReady={handleCaptchaReady}+ visible={!captchaToken}/></div>diff --git a/autogpt_platform/frontend/src/app/(platform)/login/useLoginPage.ts b/autogpt_platform/frontend/src/app/(platform)/login/useLoginPage.tsindex 00d553fe75..feedbbca57 100644--- a/autogpt_platform/frontend/src/app/(platform)/login/useLoginPage.ts+++ b/autogpt_platform/frontend/src/app/(platform)/login/useLoginPage.ts@@ -53,6 +53,8 @@ export function useLoginPage() {if (error) throw error;setFeedback(null);} catch (error) {+ setCaptchaToken(null);+ captchaRef?.reset();setIsGoogleLoading(false);const errorString = JSON.stringify(error);if (errorString.includes("not_allowed")) {@@ -94,6 +96,8 @@ export function useLoginPage() {variant: "destructive",});+ setCaptchaToken(null);+ captchaRef?.reset();return;}setFeedback(null);@@ -104,13 +108,13 @@ export function useLoginPage() {}function handleCaptchaReady(ref: TurnstileInstance) {- setCaptchaRef(ref);+ if (!captchaRef) setCaptchaRef(ref);}return {form,feedback,- captchaRef,+ captchaToken,isLoggedIn: !!user,isLoading,isCloudEnv,diff --git a/autogpt_platform/frontend/src/components/auth/Turnstile2.tsx b/autogpt_platform/frontend/src/components/auth/Turnstile2.tsxindex bb3ca9e3e2..970bb26642 100644--- a/autogpt_platform/frontend/src/components/auth/Turnstile2.tsx+++ b/autogpt_platform/frontend/src/components/auth/Turnstile2.tsx@@ -2,7 +2,7 @@import { BehaveAs, getBehaveAs } from "@/lib/utils";import { Turnstile, TurnstileInstance } from "@marsidev/react-turnstile";-import { useEffect, useRef, useState } from "react";+import { useEffect, useRef } from "react";const TURNSTILE_SITE_KEY =process.env.NEXT_PUBLIC_CLOUDFLARE_TURNSTILE_SITE_KEY || "";@@ -10,11 +10,11 @@ const TURNSTILE_SITE_KEY =type Props = {onVerified: (token: string) => void;onReady: (ref: TurnstileInstance) => void;+ visible: boolean;};export function Turnstile2(props: Props) {const captchaRef = useRef<TurnstileInstance>(null);- const [captchaToken, setCaptchaToken] = useState<string | null>(null);const behaveAs = getBehaveAs();useEffect(() => {@@ -24,11 +24,9 @@ export function Turnstile2(props: Props) {}, [captchaRef]);function handleCaptchaVerify(token: string) {- setCaptchaToken(token);props.onVerified(token);}- // Only render in cloud environmentif (behaveAs !== BehaveAs.CLOUD) {return null;}@@ -37,16 +35,13 @@ export function Turnstile2(props: Props) {return null;}- // If it is already verified, no need to render- if (captchaToken) {- return null;- }-return (- <Turnstile- ref={captchaRef}- siteKey={TURNSTILE_SITE_KEY}- onSuccess={handleCaptchaVerify}- />+ <div className={props.visible ? "" : "hidden"}>+ <Turnstile+ ref={captchaRef}+ siteKey={TURNSTILE_SITE_KEY}+ onSuccess={handleCaptchaVerify}+ />+ </div>);}