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 <hariombalhara@gmail.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 <hariombalhara@gmail.com>

* Update next.config.js

* Update next.config.js

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Hariom BalharaandDevin AI authored and GitHub committed 2025-09-03 09:33:56 +05:30
1 parent f2f10a06d9
commit 2d9c1b3fd9
1 file changed
+21
+21
View File
@@ -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));