From 54d3db00adbde0841198042abb0d47372881ed91 Mon Sep 17 00:00:00 2001 From: Franco Fantini Date: Sun, 21 Jan 2024 11:34:33 -0300 Subject: [PATCH] Feature: Email whitelist (#1221) Co-authored-by: Franco Fantini --- .env.local.example | 4 ++++ app/[locale]/login/page.tsx | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/.env.local.example b/.env.local.example index db7b92cf8f..bc57a8c821 100644 --- a/.env.local.example +++ b/.env.local.example @@ -25,3 +25,7 @@ NEXT_PUBLIC_AZURE_OPENAI_ENDPOINT= NEXT_PUBLIC_AZURE_GPT_35_TURBO_ID= NEXT_PUBLIC_AZURE_GPT_45_VISION_ID= NEXT_PUBLIC_AZURE_GPT_45_TURBO_ID= + +# General Configuration (Optional) +EMAIL_DOMAIN_WHITELIST= +EMAIL_WHITELIST= diff --git a/app/[locale]/login/page.tsx b/app/[locale]/login/page.tsx index b683de5a77..2ee092aac2 100644 --- a/app/[locale]/login/page.tsx +++ b/app/[locale]/login/page.tsx @@ -61,6 +61,21 @@ export default async function Login({ const email = formData.get("email") as string const password = formData.get("password") as string + + const emailDomainWhitelist = process.env.EMAIL_DOMAIN_WHITELIST?.split(",") ?? [] + if (emailDomainWhitelist.length > 0 && !emailDomainWhitelist.includes(email.split("@")[1])) { + return redirect( + `/login?message=Email ${email} is not allowed to sign up.` + ) + } + + const emailWhitelist = process.env.EMAIL_WHITELIST?.split(",") ?? [] + if (emailWhitelist.length > 0 && !emailWhitelist.includes(email)) { + return redirect( + `/login?message=Email ${email} is not allowed to sign up.` + ) + } + const cookieStore = cookies() const supabase = createClient(cookieStore)