mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-07 00:06:32 +08:00
allow to enable/disable email signin captcha via env variable
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Vendored
+1
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user