Compare commits

..

2 Commits

Author SHA1 Message Date
9e26fd4a0e Fix jwt-token 2025-09-15 09:54:45 +02:00
f3f3c37b75 Fix jwt-token 2025-09-15 09:11:40 +02:00

View File

@@ -44,6 +44,7 @@ class MultiTenantAuth {
* Can be from subdomain, header, or JWT * Can be from subdomain, header, or JWT
*/ */
async determineTenant(req) { async determineTenant(req) {
console.log('🚀 DETERMINE TENANT FUNCTION START');
console.log('===== DETERMINE TENANT CALLED ====='); console.log('===== DETERMINE TENANT CALLED =====');
console.log('🏢 req.user:', req.user); console.log('🏢 req.user:', req.user);
console.log('🏢 req.headers.host:', req.headers?.host); console.log('🏢 req.headers.host:', req.headers?.host);
@@ -336,33 +337,6 @@ class MultiTenantAuth {
); );
} }
/**
* Determine tenant from request (slug or subdomain)
*/
async determineTenant(req) {
try {
// Try to get tenant from subdomain first
const host = req.get('host') || '';
const subdomain = host.split('.')[0];
// If subdomain is not localhost/IP, use it as tenant slug
if (subdomain && !subdomain.match(/^(localhost|127\.0\.0\.1|\d+\.\d+\.\d+\.\d+)$/)) {
return subdomain;
}
// Fallback: get from user's tenant if authenticated
if (req.user && req.user.tenant_id) {
const tenant = await Tenant.findByPk(req.user.tenant_id);
return tenant ? tenant.slug : null;
}
return null;
} catch (error) {
console.error('Error determining tenant:', error);
return null;
}
}
/** /**
* Validate that a user has access to a specific tenant * Validate that a user has access to a specific tenant
* @param {string} userId - The user ID * @param {string} userId - The user ID