Skip to content

Commit a1141f3

Browse files
committed
[TOOL-3673] Dashboard: change Turnstile widget appearance on missing turnstile token (#6453)
1 parent 1273cc7 commit a1141f3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

apps/dashboard/src/app/login/LoginPage.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "thirdweb/react";
2020
import { createWallet, inAppWallet } from "thirdweb/wallets";
2121
import { ClientOnly } from "../../components/ClientOnly/ClientOnly";
22+
import { isVercel } from "../../lib/vercel-utils";
2223
import { ThirdwebMiniLogo } from "../components/ThirdwebMiniLogo";
2324
import { getSDKTheme } from "../components/sdk-component-theme";
2425
import { doLogin, doLogout, getLoginPayload, isLoggedIn } from "./auth-actions";
@@ -246,14 +247,17 @@ function CustomConnectEmbed(props: {
246247
}) {
247248
const { theme } = useTheme();
248249
const client = useThirdwebClient();
249-
const [turnstileToken, setTurnstileToken] = useState("");
250+
const [turnstileToken, setTurnstileToken] = useState<string | undefined>(
251+
undefined,
252+
);
253+
const [alwaysShowTurnstile, setAlwaysShowTurnstile] = useState(false);
250254

251255
return (
252256
<div className="flex flex-col items-center gap-4">
253257
<Turnstile
254258
options={{
255259
// only show if interaction is required
256-
appearance: "interaction-only",
260+
appearance: alwaysShowTurnstile ? "always" : "interaction-only",
257261
// match the theme of the rest of the app
258262
theme: theme === "light" ? "light" : "dark",
259263
}}
@@ -265,6 +269,11 @@ function CustomConnectEmbed(props: {
265269
auth={{
266270
getLoginPayload,
267271
doLogin: async (params) => {
272+
if (isVercel() && !turnstileToken) {
273+
setAlwaysShowTurnstile(true);
274+
throw new Error("Please complete the captcha.");
275+
}
276+
268277
try {
269278
const result = await doLogin(params, turnstileToken);
270279
if (result.error) {

apps/dashboard/src/app/login/auth-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function getLoginPayload(
4040

4141
export async function doLogin(
4242
payload: VerifyLoginPayloadParams,
43-
turnstileToken: string,
43+
turnstileToken: string | undefined,
4444
) {
4545
if (!THIRDWEB_API_SECRET) {
4646
throw new Error("API_SERVER_SECRET is not set");

0 commit comments

Comments
 (0)