From 54339096a459ad484df419118ac52724a0af694c Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Wed, 17 Sep 2025 19:21:09 +0200 Subject: [PATCH] Fix jwt-token --- server/routes/detectors.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/routes/detectors.js b/server/routes/detectors.js index 0ed7a47..bac32f1 100644 --- a/server/routes/detectors.js +++ b/server/routes/detectors.js @@ -227,8 +227,11 @@ async function handleDetection(req, res) { console.log(`🎯 Drone Type Details: ${droneTypeInfo.category} | Threat: ${droneTypeInfo.threat_level} | ${droneTypeInfo.description}`); console.log('🔍 Complete detection data:', JSON.stringify(detectionData, null, 2)); + // Convert device_id to string for consistent database lookup + const deviceIdString = String(detectionData.device_id); + // Check if device exists and is approved - console.log(`🔍 DEBUG: Looking for device with ID: ${detectionData.device_id} (type: ${typeof detectionData.device_id})`); + console.log(`🔍 DEBUG: Looking for device with ID: ${detectionData.device_id} (type: ${typeof detectionData.device_id}) -> converted to "${deviceIdString}" (string)`); console.log(`🔍 DEBUG: Device model being used:`, Device); console.log(`🔍 DEBUG: Sequelize instance:`, Device.sequelize.constructor.name); @@ -239,7 +242,7 @@ async function handleDetection(req, res) { console.log(` - Device ID: ${d.id} (type: ${typeof d.id}), name: ${d.name}, approved: ${d.is_approved}, active: ${d.is_active}`); }); - let device = await Device.findOne({ where: { id: detectionData.device_id } }); + let device = await Device.findOne({ where: { id: deviceIdString } }); console.log(`🔍 DEBUG: Device lookup result:`, device ? `Found device ${device.id}` : 'Device not found'); if (!device) { @@ -297,9 +300,10 @@ async function handleDetection(req, res) { isDebugDetection = true; } - // Create detection record + // Create detection record with string device_id const detectionRecord = { ...detectionData, + device_id: deviceIdString, // Use the string version for consistency server_timestamp: new Date() };