diff --git a/server/middleware/multi-tenant-auth.js b/server/middleware/multi-tenant-auth.js index a03f747..dc1c857 100644 --- a/server/middleware/multi-tenant-auth.js +++ b/server/middleware/multi-tenant-auth.js @@ -90,9 +90,15 @@ class MultiTenantAuth { // Method 5: Subdomain (tenant.yourapp.com) const hostname = req.hostname || req.headers.host || ''; if (hostname && !hostname.startsWith('localhost')) { - const subdomain = hostname.split('.')[0]; - if (subdomain && subdomain !== 'www' && subdomain !== 'api' && !subdomain.includes(':')) { - return subdomain; + const hostParts = hostname.split('.'); + // Only treat as subdomain if there are at least 2 parts (subdomain.domain.com) + // and the first part is not a common root domain + if (hostParts.length >= 3) { + const subdomain = hostParts[0]; + if (subdomain && subdomain !== 'www' && subdomain !== 'api' && !subdomain.includes(':')) { + console.log('🏢 Tenant from subdomain:', subdomain); + return subdomain; + } } }