Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(cloud): signup blocked due to turnstile (#1667)

Marc Klingen135650382c96
diff --git a/web/src/pages/auth/sign-in.tsx b/web/src/pages/auth/sign-in.tsx
index 6455bbe9c2..a24cd96c40 100644
--- a/web/src/pages/auth/sign-in.tsx
+++ b/web/src/pages/auth/sign-in.tsx
@@ -279,21 +279,24 @@ export default function SignIn({ authProviders, signUpDisabled }: PageProps) {
) : null}
<SSOButtons authProviders={authProviders} />
</div>
- {env.NEXT_PUBLIC_TURNSTILE_SITE_KEY !== undefined && (
- <>
- <Divider className="text-gray-400" />
- <Turnstile
- siteKey={env.NEXT_PUBLIC_TURNSTILE_SITE_KEY}
- options={{
- theme: "light",
- action: "sign-in",
- cData: turnstileCData,
- }}
- className="mx-auto"
- onSuccess={setTurnstileToken}
- />
- </>
- )}
+ {
+ // Turnstile exists copy-paste also on sign-up.tsx
+ env.NEXT_PUBLIC_TURNSTILE_SITE_KEY !== undefined && (
+ <>
+ <Divider className="text-gray-400" />
+ <Turnstile
+ siteKey={env.NEXT_PUBLIC_TURNSTILE_SITE_KEY}
+ options={{
+ theme: "light",
+ action: "sign-in",
+ cData: turnstileCData,
+ }}
+ className="mx-auto"
+ onSuccess={setTurnstileToken}
+ />
+ </>
+ )
+ }
<CloudPrivacyNotice action="signing in" />
</div>
diff --git a/web/src/pages/auth/sign-up.tsx b/web/src/pages/auth/sign-up.tsx
index da294cfcb3..8664255c59 100644
--- a/web/src/pages/auth/sign-up.tsx
+++ b/web/src/pages/auth/sign-up.tsx
@@ -22,11 +22,19 @@ import { CloudPrivacyNotice } from "@/src/features/auth/components/AuthCloudPriv
import { CloudRegionSwitch } from "@/src/features/auth/components/AuthCloudRegionSwitch";
import { SSOButtons, type PageProps } from "@/src/pages/auth/sign-in";
import { PasswordInput } from "@/src/components/ui/password-input";
+import { Divider } from "@tremor/react";
+import { Turnstile } from "@marsidev/react-turnstile";
// Use the same getServerSideProps function as src/pages/auth/sign-in.tsx
export { getServerSideProps } from "@/src/pages/auth/sign-in";
export default function SignIn({ authProviders }: PageProps) {
+ const [turnstileToken, setTurnstileToken] = useState<string>();
+ // Used to refresh turnstile as the token can only be used once
+ const [turnstileCData, setTurnstileCData] = useState<string>(
+ new Date().getTime().toString(),
+ );
+
const [formError, setFormError] = useState<string | null>(null);
const form = useForm<z.infer<typeof signupSchema>>({
resolver: zodResolver(signupSchema),
@@ -58,9 +66,16 @@ export default function SignIn({ authProviders }: PageProps) {
callbackUrl: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION
? "/onboarding"
: "/?getStarted=1",
+ turnstileToken,
});
} catch (err) {
setFormError("An error occurred. Please try again.");
+
+ // Refresh turnstile as the token can only be used once
+ if (env.NEXT_PUBLIC_TURNSTILE_SITE_KEY && turnstileToken) {
+ setTurnstileCData(new Date().getTime().toString());
+ setTurnstileToken(undefined);
+ }
}
}
@@ -138,6 +153,10 @@ export default function SignIn({ authProviders }: PageProps) {
type="submit"
className="w-full"
loading={form.formState.isSubmitting}
+ disabled={
+ env.NEXT_PUBLIC_TURNSTILE_SITE_KEY !== undefined &&
+ turnstileToken === undefined
+ }
>
Sign up
</Button>
@@ -149,7 +168,24 @@ export default function SignIn({ authProviders }: PageProps) {
</form>
</Form>
<SSOButtons authProviders={authProviders} action="Sign up" />
- <div className="h-5" />
+ {
+ // Turnstile exists copy-paste also on sign-up.tsx
+ env.NEXT_PUBLIC_TURNSTILE_SITE_KEY !== undefined && (
+ <>
+ <Divider className="text-gray-400" />
+ <Turnstile
+ siteKey={env.NEXT_PUBLIC_TURNSTILE_SITE_KEY}
+ options={{
+ theme: "light",
+ action: "sign-in",
+ cData: turnstileCData,
+ }}
+ className="mx-auto"
+ onSuccess={setTurnstileToken}
+ />
+ </>
+ )
+ }
<CloudPrivacyNotice action="creating an account" />
</div>