Skip to content

Commit 2d2fd6b

Browse files
authored
Only render captcha when sitekey is available (#2989)
Refs #2987
1 parent 218d30f commit 2d2fd6b

File tree

4 files changed

+166
-17
lines changed

4 files changed

+166
-17
lines changed

website/package-lock.json

Lines changed: 151 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"msw": "^1.2.1",
114114
"msw-storybook-addon": "^1.8.0",
115115
"path-browserify": "^1.0.1",
116+
"pino-pretty": "^10.0.0",
116117
"prettier": "2.8.1",
117118
"prisma": "^4.13.0",
118119
"storybook": "^7.0.5",

website/src/components/CloudflareCaptcha.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import { useColorMode } from "@chakra-ui/react";
22
import { Turnstile, TurnstileInstance, TurnstileProps } from "@marsidev/react-turnstile";
33
import { forwardRef } from "react";
4+
import { useBrowserConfig } from "src/hooks/env/BrowserEnv";
5+
import { StrictOmit } from "ts-essentials";
46

5-
export const CloudFlareCaptcha = forwardRef<TurnstileInstance, TurnstileProps>((props, ref) => {
6-
const { siteKey, ...restProps } = props;
7+
export const CloudFlareCaptcha = forwardRef<TurnstileInstance, StrictOmit<TurnstileProps, "siteKey">>((props, ref) => {
8+
const { ...restProps } = props;
79
const { colorMode } = useColorMode();
10+
const { CLOUDFLARE_CAPTCHA_SITE_KEY } = useBrowserConfig();
11+
12+
if (!CLOUDFLARE_CAPTCHA_SITE_KEY) {
13+
return null;
14+
}
15+
816
return (
917
<Turnstile
1018
ref={ref}
1119
{...restProps}
12-
siteKey={siteKey}
20+
siteKey={CLOUDFLARE_CAPTCHA_SITE_KEY}
1321
options={{
1422
theme: colorMode,
1523
...props.options,

website/src/pages/auth/signin.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import { useColorMode } from "@chakra-ui/react";
1212
import { Discord, Google } from "@icons-pack/react-simple-icons";
1313
import { TurnstileInstance } from "@marsidev/react-turnstile";
14-
import { boolean } from "boolean";
1514
import { Bug, Mail } from "lucide-react";
1615
import { GetServerSideProps } from "next";
1716
import Head from "next/head";
@@ -64,11 +63,8 @@ interface SigninProps {
6463

6564
function Signin({ providers }: SigninProps) {
6665
const router = useRouter();
67-
const {
68-
ENABLE_EMAIL_SIGNIN: enableEmailSignin,
69-
ENABLE_EMAIL_SIGNIN_CAPTCHA: enableEmailSigninCaptcha,
70-
CLOUDFLARE_CAPTCHA_SITE_KEY: cloudflareCaptchaSiteKey,
71-
} = useBrowserConfig();
66+
const { ENABLE_EMAIL_SIGNIN: enableEmailSignin, ENABLE_EMAIL_SIGNIN_CAPTCHA: enableEmailSigninCaptcha } =
67+
useBrowserConfig();
7268
const { discord, email, google, credentials } = providers;
7369
const [error, setError] = useState("");
7470

@@ -96,11 +92,7 @@ function Signin({ providers }: SigninProps) {
9692
<Stack spacing="2">
9793
{credentials && <DebugSigninForm providerId={credentials.id} />}
9894
{email && enableEmailSignin && (
99-
<EmailSignInForm
100-
providerId={email.id}
101-
enableEmailSigninCaptcha={enableEmailSigninCaptcha}
102-
cloudflareCaptchaSiteKey={cloudflareCaptchaSiteKey}
103-
/>
95+
<EmailSignInForm providerId={email.id} enableEmailSigninCaptcha={enableEmailSigninCaptcha} />
10496
)}
10597
{discord && (
10698
<Button
@@ -156,11 +148,9 @@ export default Signin;
156148
const EmailSignInForm = ({
157149
providerId,
158150
enableEmailSigninCaptcha,
159-
cloudflareCaptchaSiteKey,
160151
}: {
161152
providerId: string;
162153
enableEmailSigninCaptcha: boolean;
163-
cloudflareCaptchaSiteKey: string;
164154
}) => {
165155
const {
166156
register,
@@ -196,7 +186,6 @@ const EmailSignInForm = ({
196186
</FormControl>
197187
{enableEmailSigninCaptcha && (
198188
<CloudFlareCaptcha
199-
siteKey={cloudflareCaptchaSiteKey}
200189
options={{ size: "invisible" }}
201190
ref={captcha}
202191
onSuccess={() => setCaptchaSuccess(true)}

0 commit comments

Comments
 (0)