Fix jwt-token
This commit is contained in:
@@ -279,6 +279,33 @@ class MultiTenantAuth {
|
||||
{ expiresIn: '24h' }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MultiTenantAuth;
|
||||
|
||||
Reference in New Issue
Block a user