import { INSTANCE_SETTINGS_ID, REGISTRATION_MODES, type RegistrationMode } from '../../drizzle/schema'; import { db } from '../lib/db'; /** * DISABLE_SIGNUP in the environment wins over whatever admins pick in the UI, * so a deployment that was locked down this way stays locked down. */ export const isRegistrationLocked = (): boolean => { const value = process.env.DISABLE_SIGNUP?.toLowerCase(); return value === 'true' || value === '1'; }; export const getRegistrationMode = async (): Promise => { if (isRegistrationLocked()) return 'closed'; const row = await db.query.instanceSettings.findFirst({ where: { id: INSTANCE_SETTINGS_ID, }, }); const mode = row?.registration; // instances that never touched the setting keep taking sign ups like before return mode !== undefined && REGISTRATION_MODES.includes(mode) ? mode : 'open'; };