Skip to content

Commit

Permalink
disable multiple team creation for self-hosters
Browse files Browse the repository at this point in the history
  • Loading branch information
KMKoushik committed Oct 19, 2024
1 parent 2391d1c commit 2db31cd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 36 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ NEXTAUTH_SECRET=""
API_RATE_LIMIT=2

NEXT_PUBLIC_IS_CLOUD=false
NEXT_PUBLIC_SELF_HOSTED_ALLOW_NEW_USERS=false
4 changes: 4 additions & 0 deletions apps/web/src/components/team/CreateTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Input } from "@unsend/ui/src/input";
import { Spinner } from "@unsend/ui/src/spinner";
import { api } from "~/trpc/react";
import { useRouter } from "next/navigation";
import { toast } from "@unsend/ui/src/toaster";

const FormSchema = z.object({
name: z.string().min(2, {
Expand All @@ -43,6 +44,9 @@ export default function CreateTeam() {
utils.team.invalidate();
router.replace("/dashboard");
},
onError: (e) => {
toast.error(e.message);
},
});
}

Expand Down
19 changes: 0 additions & 19 deletions apps/web/src/components/team/TeamCreationDisabled.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions apps/web/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ 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 @@ -91,8 +87,6 @@ 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: 0 additions & 9 deletions apps/web/src/providers/dashboard-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 @@ -27,14 +26,6 @@ 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
12 changes: 12 additions & 0 deletions apps/web/src/server/api/routers/team.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { TRPCError } from "@trpc/server";
import { z } from "zod";
import { env } from "~/env";

import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";

Expand All @@ -21,6 +23,16 @@ export const teamRouter = createTRPCRouter({
return;
}

if (!env.NEXT_PUBLIC_IS_CLOUD) {
const _team = await ctx.db.team.findFirst();
if (_team) {
throw new TRPCError({
message: "Can't have multiple teams in self hosted version",
code: "UNAUTHORIZED",
});
}
}

return ctx.db.team.create({
data: {
name: input.name,
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"S3_COMPATIBLE_ACCESS_KEY",
"S3_COMPATIBLE_SECRET_KEY",
"S3_COMPATIBLE_API_URL",
"S3_COMPATIBLE_PUBLIC_URL"
"S3_COMPATIBLE_PUBLIC_URL",
"ENABLE_PRISMA_CLIENT"
]
},
"lint": {
Expand Down

0 comments on commit 2db31cd

Please sign in to comment.