From 2d9c1b3fd9b7ba0014c61557ffcb5dd5cadc9bef Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Wed, 3 Sep 2025 09:33:56 +0530 Subject: [PATCH] feat: Make single org setup more reliable by automatically adjusting RESERVED_SUBDOMAINS and ORGANIZATIONS_ENABLED (#23448) * feat: add build validation for SINGLE_ORG_SLUG and auto-enable organizations - Add build-time validation to prevent SINGLE_ORG_SLUG from conflicting with RESERVED_SUBDOMAINS - Auto-enable ORGANIZATIONS_ENABLED when SINGLE_ORG_SLUG is set - Validation throws clear error message with list of reserved subdomains - Follows existing environment validation patterns in next.config.js Co-Authored-By: hariom@cal.com * refactor: change SINGLE_ORG_SLUG validation from error to warning - Replace build-crashing error with clear warning message - Ignore RESERVED_SUBDOMAINS when SINGLE_ORG_SLUG is set since they don't make sense together - Keep auto-enabling ORGANIZATIONS_ENABLED functionality - Build continues successfully instead of failing Co-Authored-By: hariom@cal.com * Update next.config.js * Update next.config.js --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/web/next.config.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apps/web/next.config.js b/apps/web/next.config.js index 4f8c665613..e594bc5c35 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -11,6 +11,9 @@ const { orgUserTypeRoutePath, orgUserTypeEmbedRoutePath, } = require("./pagesAndRewritePaths"); + +adjustEnvVariables(); + if (!process.env.NEXTAUTH_SECRET) throw new Error("Please set NEXTAUTH_SECRET"); if (!process.env.CALENDSO_ENCRYPTION_KEY) throw new Error("Please set CALENDSO_ENCRYPTION_KEY"); const isOrganizationsEnabled = @@ -715,4 +718,22 @@ const nextConfig = (phase) => { }; }; +function adjustEnvVariables() { + if (process.env.NEXT_PUBLIC_SINGLE_ORG_SLUG) { + if (process.env.RESERVED_SUBDOMAINS) { + // It is better to ignore it completely so that accidentally if the org slug is itself in Reserved Subdomain that doesn't cause the booking pages to start giving 404s + console.warn( + `⚠️ WARNING: RESERVED_SUBDOMAINS is ignored when SINGLE_ORG_SLUG is set. Single org mode doesn't need to use reserved subdomain validation.` + ); + delete process.env.RESERVED_SUBDOMAINS; + } + + if (!process.env.ORGANIZATIONS_ENABLED) { + // This is basically a consent to add rewrites related to organizations. So, if single org slug mode is there, we have the consent already. + console.log("Auto-enabling ORGANIZATIONS_ENABLED because SINGLE_ORG_SLUG is set"); + process.env.ORGANIZATIONS_ENABLED = "1"; + } + } +} + module.exports = (phase) => plugins.reduce((acc, next) => next(acc), nextConfig(phase));