From 443329b99fc581f3f49169bb7a177cc3ba757f14 Mon Sep 17 00:00:00 2001 From: Jeff Loiselle Date: Fri, 13 Jan 2023 19:42:13 -0500 Subject: [PATCH] disables signups via env variable (#6212) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * disables signups via env variable * Apply suggestions from code review Co-authored-by: Peer Richelsen Co-authored-by: Omar López --- .env.example | 3 +++ apps/web/pages/api/auth/signup.ts | 5 +++++ apps/web/pages/auth/login.tsx | 8 +++++++- apps/web/pages/signup.tsx | 6 ++++++ turbo.json | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 0db0a49ec3..14a7a32f42 100644 --- a/.env.example +++ b/.env.example @@ -152,3 +152,6 @@ SENTRY_IGNORE_API_RESOLUTION_ERROR= NEXT_PUBLIC_APP_NAME="Cal.com" NEXT_PUBLIC_SUPPORT_MAIL_ADDRESS="help@cal.com" NEXT_PUBLIC_COMPANY_NAME="Cal.com, Inc." +# Set this to true in to disable new signups +# NEXT_PUBLIC_DISABLE_SIGNUP=true +NEXT_PUBLIC_DISABLE_SIGNUP= diff --git a/apps/web/pages/api/auth/signup.ts b/apps/web/pages/api/auth/signup.ts index 9442f1f707..7c9a347633 100644 --- a/apps/web/pages/api/auth/signup.ts +++ b/apps/web/pages/api/auth/signup.ts @@ -12,6 +12,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) return; } + if (process.env.NEXT_PUBLIC_DISABLE_SIGNUP === "true") { + res.status(403).json({ message: "Signup is disabled" }); + return; + } + const data = req.body; const { email, password } = data; const username = slugify(data.username); diff --git a/apps/web/pages/auth/login.tsx b/apps/web/pages/auth/login.tsx index 0442917bf8..1810c7e50a 100644 --- a/apps/web/pages/auth/login.tsx +++ b/apps/web/pages/auth/login.tsx @@ -115,7 +115,13 @@ export default function Login({ description={t("login")} showLogo heading={twoFactorRequired ? t("2fa_code") : t("welcome_back")} - footerText={twoFactorRequired ? TwoFactorFooter : LoginFooter}> + footerText={ + twoFactorRequired + ? TwoFactorFooter + : process.env.NEXT_PUBLIC_DISABLE_SIGNUP !== "true" + ? LoginFooter + : null + }>
diff --git a/apps/web/pages/signup.tsx b/apps/web/pages/signup.tsx index cbe212b0e3..9582610cb6 100644 --- a/apps/web/pages/signup.tsx +++ b/apps/web/pages/signup.tsx @@ -149,6 +149,12 @@ export const getServerSideProps = async (ctx: GetServerSidePropsContext) => { prepopulateFormValues: undefined, }; + if (process.env.NEXT_PUBLIC_DISABLE_SIGNUP === "true") { + return { + notFound: true, + }; + } + // no token given, treat as a normal signup without verification token if (!token) { return { diff --git a/turbo.json b/turbo.json index 0ee36fce54..5b36ea1130 100644 --- a/turbo.json +++ b/turbo.json @@ -225,6 +225,7 @@ "$NEXT_PUBLIC_SUPPORT_MAIL_ADDRESS", "$NEXT_PUBLIC_COMPANY_NAME", "$NEXT_PUBLIC_SENDER_ID", + "$NEXT_PUBLIC_DISABLE_SIGNUP", "$NEXTAUTH_COOKIE_DOMAIN", "$NEXTAUTH_SECRET", "$NEXTAUTH_URL",