From 95fc3a0825795b15a387707ac8cb2cb0df3f4c27 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Fri, 22 Mar 2024 15:31:55 +0000 Subject: feature: Add an option to disable new signups --- packages/trpc/routers/users.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'packages/trpc') diff --git a/packages/trpc/routers/users.ts b/packages/trpc/routers/users.ts index db06c0ad..1e7a83a6 100644 --- a/packages/trpc/routers/users.ts +++ b/packages/trpc/routers/users.ts @@ -5,6 +5,7 @@ import { z } from "zod"; import { SqliteError } from "@hoarder/db"; import { users } from "@hoarder/db/schema"; +import serverConfig from "@hoarder/shared/config"; import { hashPassword, validatePassword } from "../auth"; import { @@ -27,6 +28,12 @@ export const usersAppRouter = router({ }), ) .mutation(async ({ input, ctx }) => { + if (serverConfig.auth.disableSignups) { + throw new TRPCError({ + code: "FORBIDDEN", + message: "Signups are disabled in server config", + }); + } // TODO: This is racy, but that's probably fine. const [{ count: userCount }] = await ctx.db .select({ count: count() }) -- cgit v1.2.3-70-g09d2