Fix jwt-token
This commit is contained in:
@@ -366,8 +366,6 @@ class MultiTenantAuth {
|
||||
try {
|
||||
const { User, Tenant } = this.models || require('../models');
|
||||
|
||||
console.log('🔍 validateTenantAccess called with:', { userId, tenantSlug });
|
||||
|
||||
// Find the user
|
||||
const user = await User.findByPk(userId, {
|
||||
include: [{
|
||||
@@ -376,31 +374,12 @@ class MultiTenantAuth {
|
||||
}]
|
||||
});
|
||||
|
||||
console.log('🔍 Found user:', user ? {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
tenant_id: user.tenant_id,
|
||||
tenant: user.tenant ? {
|
||||
id: user.tenant.id,
|
||||
slug: user.tenant.slug,
|
||||
name: user.tenant.name
|
||||
} : null
|
||||
} : null);
|
||||
|
||||
if (!user) {
|
||||
console.log('❌ User not found');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if user's tenant matches the requested tenant
|
||||
const result = user.tenant && user.tenant.slug === tenantSlug;
|
||||
console.log('🔍 Validation result:', {
|
||||
userTenantSlug: user.tenant?.slug,
|
||||
requestedSlug: tenantSlug,
|
||||
result
|
||||
});
|
||||
|
||||
return result;
|
||||
return user.tenant && user.tenant.slug === tenantSlug;
|
||||
} catch (error) {
|
||||
console.error('Error validating tenant access:', error);
|
||||
return false;
|
||||
|
||||
@@ -267,7 +267,22 @@ async function createTestDetection(detectionData = {}) {
|
||||
...detectionData
|
||||
};
|
||||
|
||||
return await DroneDetection.create(defaultDetectionData);
|
||||
// Remove any id field to let Sequelize auto-generate UUID
|
||||
delete defaultDetectionData.id;
|
||||
|
||||
// Additional safety check - remove any UUIDV4 function objects
|
||||
Object.keys(defaultDetectionData).forEach(key => {
|
||||
if (defaultDetectionData[key] && typeof defaultDetectionData[key] === 'object' &&
|
||||
defaultDetectionData[key].constructor && defaultDetectionData[key].constructor.name === 'UUIDV4') {
|
||||
delete defaultDetectionData[key];
|
||||
}
|
||||
});
|
||||
|
||||
// Try manual UUID generation as a workaround
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const detectionWithId = { ...defaultDetectionData, id: uuidv4() };
|
||||
|
||||
return await DroneDetection.create(detectionWithId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user