Fix jwt-token

This commit is contained in:
2025-09-15 07:53:10 +02:00
parent a3c12efcf0
commit b643724706
2 changed files with 9 additions and 2 deletions

View File

@@ -44,6 +44,7 @@ class MultiTenantAuth {
async determineTenant(req) {
// Method 1: From authenticated user (highest priority)
if (req.user && req.user.tenantId) {
console.log('🏢 Tenant from req.user.tenantId:', req.user.tenantId);
return req.user.tenantId;
}
@@ -68,9 +69,11 @@ class MultiTenantAuth {
// Method 4: x-forwarded-host header (for proxied requests)
const forwardedHost = req.headers['x-forwarded-host'];
console.log('🏢 x-forwarded-host header:', forwardedHost);
if (forwardedHost) {
const subdomain = forwardedHost.split('.')[0];
if (subdomain && subdomain !== 'www' && subdomain !== 'api' && !subdomain.includes(':')) {
console.log('🏢 Tenant from x-forwarded-host:', subdomain);
return subdomain;
}
}
@@ -86,7 +89,9 @@ class MultiTenantAuth {
// Method 6: URL path (/tenant2/api/...)
const pathSegments = (req.path || req.url || '').split('/').filter(segment => segment);
console.log('🏢 URL path segments:', pathSegments, 'from path:', req.path, 'or url:', req.url);
if (pathSegments.length > 0 && pathSegments[0] !== 'api') {
console.log('🏢 Tenant from URL path:', pathSegments[0]);
return pathSegments[0];
}
@@ -97,9 +102,11 @@ class MultiTenantAuth {
// Return null for localhost without tenant info
if (hostname && hostname.startsWith('localhost')) {
console.log('🏢 Localhost detected, returning null');
return null;
}
console.log('🏢 No tenant determined, returning null');
// Default to null
return null;
}