From 94e365c1bbb3b4114854d0d14a32f98c8f75c2c4 Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Mon, 15 Sep 2025 10:08:08 +0200 Subject: [PATCH] Fix jwt-token --- server/middleware/multi-tenant-auth.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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; + } } }