From 2391d1c30634c796721a0eb283570276168626cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavi=20Vel=C3=A0squez?= Date: Sat, 19 Oct 2024 22:23:14 +0200 Subject: [PATCH] Add environment variable to enable team creation for new users in self-hosted deployments (#74) --- .env.example | 3 ++- .../components/team/TeamCreationDisabled.tsx | 19 +++++++++++++++++++ apps/web/src/env.js | 6 ++++++ apps/web/src/providers/dashboard-provider.tsx | 9 +++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 apps/web/src/components/team/TeamCreationDisabled.tsx diff --git a/.env.example b/.env.example index 49825a9..351a5f7 100644 --- a/.env.example +++ b/.env.example @@ -17,4 +17,5 @@ NEXTAUTH_SECRET="" API_RATE_LIMIT=2 -NEXT_PUBLIC_IS_CLOUD=false \ No newline at end of file +NEXT_PUBLIC_IS_CLOUD=false +NEXT_PUBLIC_SELF_HOSTED_ALLOW_NEW_USERS=false \ No newline at end of file diff --git a/apps/web/src/components/team/TeamCreationDisabled.tsx b/apps/web/src/components/team/TeamCreationDisabled.tsx new file mode 100644 index 0000000..a61d821 --- /dev/null +++ b/apps/web/src/components/team/TeamCreationDisabled.tsx @@ -0,0 +1,19 @@ +"use client"; + +export default function TeamCreationDisabled() { + + return ( +
+
+
+

Cannot sign up

+
+
+

+ Team creation is disabled. Please contact your administrator. +

+
+
+
+ ); +} diff --git a/apps/web/src/env.js b/apps/web/src/env.js index 116538a..59fd4b8 100644 --- a/apps/web/src/env.js +++ b/apps/web/src/env.js @@ -66,6 +66,10 @@ export const env = createEnv({ .string() .default("false") .transform((str) => str === "true"), + NEXT_PUBLIC_SELF_HOSTED_ALLOW_NEW_USERS: z + .string() + .default("false") + .transform((str) => str === "true"), }, /** @@ -87,6 +91,8 @@ export const env = createEnv({ AWS_DEFAULT_REGION: process.env.AWS_DEFAULT_REGION, API_RATE_LIMIT: process.env.API_RATE_LIMIT, NEXT_PUBLIC_IS_CLOUD: process.env.NEXT_PUBLIC_IS_CLOUD, + NEXT_PUBLIC_SELF_HOSTED_ALLOW_NEW_USERS: + process.env.NEXT_PUBLIC_SELF_HOSTED_ALLOW_NEW_USERS, ADMIN_EMAIL: process.env.ADMIN_EMAIL, DISCORD_WEBHOOK_URL: process.env.DISCORD_WEBHOOK_URL, REDIS_URL: process.env.REDIS_URL, diff --git a/apps/web/src/providers/dashboard-provider.tsx b/apps/web/src/providers/dashboard-provider.tsx index 00f93cd..933fb70 100644 --- a/apps/web/src/providers/dashboard-provider.tsx +++ b/apps/web/src/providers/dashboard-provider.tsx @@ -4,6 +4,7 @@ import { useSession } from "next-auth/react"; import { FullScreenLoading } from "~/components/FullScreenLoading"; import { AddSesSettings } from "~/components/settings/AddSesSettings"; import CreateTeam from "~/components/team/CreateTeam"; +import TeamCreationDisabled from "~/components/team/TeamCreationDisabled"; import { env } from "~/env"; import { api } from "~/trpc/react"; @@ -26,6 +27,14 @@ export const DashboardProvider = ({ return ; } + if ( + !env.NEXT_PUBLIC_IS_CLOUD && + !env.NEXT_PUBLIC_SELF_HOSTED_ALLOW_NEW_USERS && + (!teams || teams.length === 0) + ) { + return ; + } + if ( settings?.length === 0 && (!env.NEXT_PUBLIC_IS_CLOUD || session?.user.isAdmin)