Fix jwt-token

This commit is contained in:
2025-09-15 06:38:23 +02:00
parent 60f8867cd2
commit 2851a2e9c8
4 changed files with 71 additions and 2 deletions

View File

@@ -306,6 +306,36 @@ class MultiTenantAuth {
return null;
}
}
/**
* Validate that a user has access to a specific tenant
* @param {string} userId - The user ID
* @param {string} tenantSlug - The tenant slug
* @returns {boolean} - True if user has access to tenant
*/
async validateTenantAccess(userId, tenantSlug) {
try {
const { User, Tenant } = require('../models');
// Find the user
const user = await User.findByPk(userId, {
include: [{
model: Tenant,
as: 'tenant'
}]
});
if (!user) {
return false;
}
// Check if user's tenant matches the requested tenant
return user.tenant && user.tenant.slug === tenantSlug;
} catch (error) {
console.error('Error validating tenant access:', error);
return false;
}
}
}
module.exports = MultiTenantAuth;