Skip to content

Commit

Permalink
Add environment variable to enable team creation for new users in sel…
Browse files Browse the repository at this point in the history
…f-hosted deployments (#74)
  • Loading branch information
xvelasqu authored Oct 19, 2024
1 parent b817e11 commit 2391d1c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ NEXTAUTH_SECRET=""

API_RATE_LIMIT=2

NEXT_PUBLIC_IS_CLOUD=false
NEXT_PUBLIC_IS_CLOUD=false
NEXT_PUBLIC_SELF_HOSTED_ALLOW_NEW_USERS=false
19 changes: 19 additions & 0 deletions apps/web/src/components/team/TeamCreationDisabled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use client";

export default function TeamCreationDisabled() {

return (
<div className="flex items-center justify-center min-h-screen ">
<div className=" w-[300px] flex flex-col gap-8">
<div>
<h1 className="text-2xl font-semibold text-center">Cannot sign up</h1>
</div>
<div>
<p className="text-center">
Team creation is disabled. Please contact your administrator.
</p>
</div>
</div>
</div>
);
}
6 changes: 6 additions & 0 deletions apps/web/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},

/**
Expand All @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions apps/web/src/providers/dashboard-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -26,6 +27,14 @@ export const DashboardProvider = ({
return <FullScreenLoading />;
}

if (
!env.NEXT_PUBLIC_IS_CLOUD &&
!env.NEXT_PUBLIC_SELF_HOSTED_ALLOW_NEW_USERS &&
(!teams || teams.length === 0)
) {
return <TeamCreationDisabled />;
}

if (
settings?.length === 0 &&
(!env.NEXT_PUBLIC_IS_CLOUD || session?.user.isAdmin)
Expand Down

0 comments on commit 2391d1c

Please sign in to comment.