import "server-only"; import { prisma } from "@/lib/db"; import { SignupMode } from "@/lib/generated/prisma/enums"; // Fixed id of the one-and-only SiteSettings row (see prisma/schema.prisma). const SETTINGS_ID = "singleton"; /** * Reads the site's sign-up mode. No row means the settings were never * touched, which is the same as OPEN -- today's default behavior -- so * this never creates a row just to read it. */ export async function getSignupMode(): Promise { const settings = await prisma.siteSettings.findUnique({ where: { id: SETTINGS_ID }, select: { signupMode: true }, }); return settings?.signupMode ?? SignupMode.OPEN; } /** Creates the settings row on first write, updates it on every write after. */ export async function setSignupMode(mode: SignupMode): Promise { await prisma.siteSettings.upsert({ where: { id: SETTINGS_ID }, update: { signupMode: mode }, create: { id: SETTINGS_ID, signupMode: mode }, }); }