Fix jwt-token
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user