allow to enable/disable email signin captcha via env variable

This commit is contained in:
notmd
2023-01-29 23:28:26 +07:00
parent fce158b8d3
commit fb26a52c2c
5 changed files with 20 additions and 7 deletions
+1
View File
@@ -127,6 +127,7 @@ services:
- DEBUG_LOGIN=true
- NEXT_PUBLIC_CLOUDFARE_CAPTCHA_SITE_KEY=1x00000000000000000000AA
- CLOUDFLARE_CAPTCHA_SERCERT_KEY=1x0000000000000000000000000000000AA
- NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN_CAPTCHA=true
depends_on:
webdb:
condition: service_healthy
+1
View File
@@ -17,3 +17,4 @@ EMAIL_FROM=info@example.com
NEXT_PUBLIC_CLOUDFLARE_CAPTCHA_SITE_KEY=1x00000000000000000000AA
CLOUDFLARE_CAPTCHA_SERCERT_KEY=1x0000000000000000000000000000000AA
NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN_CAPTCHA=true
+1 -1
View File
@@ -161,7 +161,7 @@ export default function auth(req: NextApiRequest, res: NextApiResponse) {
callbacks: {
...authOptions.callbacks,
async signIn({ account }) {
if (account.provider !== "email") {
if (account.provider !== "email" || !boolean(process.env.NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN_CAPTCHA)) {
return true;
}
+16 -6
View File
@@ -1,6 +1,7 @@
import { Button, ButtonProps, Input, Stack, useColorModeValue } from "@chakra-ui/react";
import { useColorMode } from "@chakra-ui/react";
import { TurnstileInstance } from "@marsidev/react-turnstile";
import { boolean } from "boolean";
import { Bug, Github, Mail } from "lucide-react";
import { GetServerSideProps } from "next";
import Head from "next/head";
@@ -144,6 +145,8 @@ Signin.getLayout = (page) => (
export default Signin;
const emailSigninCaptcha = boolean(process.env.NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN_CAPTCHA);
const EmailSignInForm = ({ providerId }: { providerId: string }) => {
const { register, handleSubmit } = useForm<{ email: string }>();
const captcha = useRef<TurnstileInstance>();
@@ -166,12 +169,19 @@ const EmailSignInForm = ({ providerId }: { providerId: string }) => {
placeholder="Email Address"
{...register("email")}
/>
<CloudFlareCatpcha
options={{ size: "invisible" }}
ref={captcha}
onSuccess={() => setCaptchaSuccess(true)}
></CloudFlareCatpcha>
<SigninButton data-cy="signin-email-button" leftIcon={<Mail />} mt="4" disabled={!captchaSuccess}>
{emailSigninCaptcha && (
<CloudFlareCatpcha
options={{ size: "invisible" }}
ref={captcha}
onSuccess={() => setCaptchaSuccess(true)}
></CloudFlareCatpcha>
)}
<SigninButton
data-cy="signin-email-button"
leftIcon={<Mail />}
mt="4"
disabled={!captchaSuccess && emailSigninCaptcha}
>
Continue with Email
</SigninButton>
</Stack>
+1
View File
@@ -4,6 +4,7 @@ declare global {
NODE_ENV: "development" | "production";
NEXT_PUBLIC_CLOUDFLARE_CAPTCHA_SITE_KEY: string;
CLOUDFLARE_CAPTCHA_SERCERT_KEY: string;
NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN_CAPTCHA: boolean;
}
}
}