From 81b7d52e6400a2606750b4d86603ac5264cdc4e8 Mon Sep 17 00:00:00 2001 From: Hendrik Belitz Date: Fri, 6 Mar 2026 10:05:18 +0100 Subject: [PATCH] Do not apply shortname for system tenant generateBaseUrl Do not remove domain name parts if hostname already is a subdomain --- src/lib/server/email/email-service.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/lib/server/email/email-service.ts b/src/lib/server/email/email-service.ts index 7426e36..f3bbf83 100644 --- a/src/lib/server/email/email-service.ts +++ b/src/lib/server/email/email-service.ts @@ -409,18 +409,10 @@ export function generateBaseUrl(requestUrl: URL, tenant: SelectTenant | null): s return `${protocol}//${hostname}${port}`; } - // In production, handle tenant subdomains - if (tenant?.shortName) { - const parts = hostname.split("."); - - if (parts.length > 2) { - // Complex subdomain - use only the last two parts (domain.tld) and add tenant - const domain = parts.slice(-2).join("."); - return `${protocol}//${tenant.shortName}.${domain}${port}`; - } else { - // Main domain, prepend tenant subdomain - return `${protocol}//${tenant.shortName}.${hostname}${port}`; - } + // In production, handle tenant subdomains. + // Exclude the system tenant when determining if we should use the tenant's shortName for the URL, as the system tenant does not have a shortName and should use the main domain. + if (tenant?.shortName && tenant.id !== "system") { + return `${protocol}//${tenant.shortName}.${hostname}${port}`; } // For global admin or no tenant, use main domain