Fix jwt-token

This commit is contained in:
2025-09-15 14:24:17 +02:00
parent 6034aac1a7
commit c8428d5415
2 changed files with 17 additions and 23 deletions

View File

@@ -366,8 +366,6 @@ class MultiTenantAuth {
try { try {
const { User, Tenant } = this.models || require('../models'); const { User, Tenant } = this.models || require('../models');
console.log('🔍 validateTenantAccess called with:', { userId, tenantSlug });
// Find the user // Find the user
const user = await User.findByPk(userId, { const user = await User.findByPk(userId, {
include: [{ 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) { if (!user) {
console.log('❌ User not found');
return false; return false;
} }
// Check if user's tenant matches the requested tenant // Check if user's tenant matches the requested tenant
const result = user.tenant && user.tenant.slug === tenantSlug; return user.tenant && user.tenant.slug === tenantSlug;
console.log('🔍 Validation result:', {
userTenantSlug: user.tenant?.slug,
requestedSlug: tenantSlug,
result
});
return result;
} catch (error) { } catch (error) {
console.error('Error validating tenant access:', error); console.error('Error validating tenant access:', error);
return false; return false;

View File

@@ -267,7 +267,22 @@ async function createTestDetection(detectionData = {}) {
...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);
} }
/** /**