Fix jwt-token

This commit is contained in:
2025-08-28 10:06:21 +02:00
parent 7898cfa7b4
commit ca89e43614

View File

@@ -64,6 +64,14 @@ const detectorSchema = Joi.alternatives().try(
// POST /api/detectors - Unified endpoint for heartbeats and detections
router.post('/', validateRequest(detectorSchema), async (req, res) => {
try {
// Log the full incoming payload for debugging
console.log('📦 Full payload received:', JSON.stringify(req.body, null, 2));
console.log('📡 Request headers:', JSON.stringify({
'user-agent': req.headers['user-agent'],
'content-type': req.headers['content-type'],
'content-length': req.headers['content-length']
}, null, 2));
// Determine if this is a heartbeat or detection based on payload
if (req.body.type === 'heartbeat') {
return await handleHeartbeat(req, res);
@@ -89,6 +97,7 @@ async function handleHeartbeat(req, res) {
const { type, key, device_id, ...heartbeatData } = req.body;
console.log(`💓 Heartbeat received from device key: ${key}`);
console.log('💗 Complete heartbeat data:', JSON.stringify(req.body, null, 2));
// If device_id is not provided, try to find device by key
let deviceId = device_id;
@@ -183,6 +192,7 @@ async function handleDetection(req, res) {
const detectionData = req.body;
console.log(`🚁 Drone detection received from device ${detectionData.device_id}: drone_id=${detectionData.drone_id}, type=${detectionData.drone_type}, rssi=${detectionData.rssi}`);
console.log('🔍 Complete detection data:', JSON.stringify(detectionData, null, 2));
// Check if device exists and is approved
let device = await Device.findOne({ where: { id: detectionData.device_id } });