From 0b9b8ed927cbfa0aadfe3f8fe046a3f167656294 Mon Sep 17 00:00:00 2001 From: notmd Date: Thu, 2 Feb 2023 00:29:46 +0700 Subject: [PATCH] allow to enable/disable email sigin via env variable --- docker-compose.yaml | 1 + website/.env | 1 + website/src/pages/api/auth/[...nextauth].ts | 4 ++++ website/src/pages/auth/signin.tsx | 4 +++- website/types/env.d.ts | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 9a0202e7..57a50191 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -128,6 +128,7 @@ services: - NEXT_PUBLIC_CLOUDFARE_CAPTCHA_SITE_KEY=1x00000000000000000000AA - CLOUDFLARE_CAPTCHA_SERCERT_KEY=1x0000000000000000000000000000000AA - NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN_CAPTCHA=true + - NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN=true depends_on: webdb: condition: service_healthy diff --git a/website/.env b/website/.env index e81374e7..2579036f 100644 --- a/website/.env +++ b/website/.env @@ -21,3 +21,4 @@ EMAIL_FROM=info@example.com NEXT_PUBLIC_CLOUDFLARE_CAPTCHA_SITE_KEY=1x00000000000000000000AA CLOUDFLARE_CAPTCHA_SERCERT_KEY=1x0000000000000000000000000000000AA NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN_CAPTCHA=false +NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN=true diff --git a/website/src/pages/api/auth/[...nextauth].ts b/website/src/pages/api/auth/[...nextauth].ts index 5a316256..5b763b2c 100644 --- a/website/src/pages/api/auth/[...nextauth].ts +++ b/website/src/pages/api/auth/[...nextauth].ts @@ -165,6 +165,10 @@ export default function auth(req: NextApiRequest, res: NextApiResponse) { return true; } + if (account.provider === "email" && !boolean(process.env.NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN)) { + return false; + } + const captcha = req.body.captcha; const res = await checkCaptcha(captcha, getIp(req)); diff --git a/website/src/pages/auth/signin.tsx b/website/src/pages/auth/signin.tsx index b65fa742..62cd93f7 100644 --- a/website/src/pages/auth/signin.tsx +++ b/website/src/pages/auth/signin.tsx @@ -80,7 +80,9 @@ function Signin({ providers }: SigninProps) { {credentials && } - {email && } + {email && boolean(process.env.NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN) && ( + + )} {discord && (