Fix jwt-token

This commit is contained in:
2025-09-13 15:32:50 +02:00
parent 3a6e98d792
commit cd159239ed
7 changed files with 539 additions and 67 deletions

View File

@@ -125,45 +125,15 @@ async function handleHeartbeat(req, res) {
let device = await Device.findOne({ where: { id: deviceId } });
if (!device) {
// Create new device as unapproved with coordinates if provided
const deviceData = {
id: deviceId,
name: `Device ${deviceId}`,
last_heartbeat: new Date(),
is_approved: false
};
// Device not found - reject heartbeat and require manual registration
console.log(`<EFBFBD> Heartbeat rejected from unknown device ${deviceId} - device must be manually registered first`);
// Add coordinates if provided in heartbeat
if (geo_lat && geo_lon) {
deviceData.geo_lat = geo_lat;
deviceData.geo_lon = geo_lon;
console.log(`📍 Setting device coordinates: ${geo_lat}, ${geo_lon}`);
}
// Add location description if provided
if (location_description) {
deviceData.location_description = location_description;
console.log(`📍 Setting device location: ${location_description}`);
}
device = await Device.create(deviceData);
// Emit notification for new device requiring approval
req.io.emit('new_device_pending', {
device_id: deviceId,
device_key: key,
timestamp: new Date().toISOString(),
message: `New device ${deviceId} (${key}) requires approval`
});
console.log(`⚠️ New unapproved device ${deviceId} created, awaiting approval`);
return res.status(202).json({
return res.status(404).json({
success: false,
error: 'Device not approved',
message: 'Device has been registered but requires approval before it can send data',
error: 'Device not registered',
message: 'Device not found. Please register the device manually through the UI before sending data.',
device_id: deviceId,
approval_required: true
registration_required: true
});
}
@@ -243,32 +213,15 @@ async function handleDetection(req, res) {
let device = await Device.findOne({ where: { id: detectionData.device_id } });
if (!device) {
// Create new device as unapproved
device = await Device.create({
id: detectionData.device_id,
name: `Device ${detectionData.device_id}`,
geo_lat: detectionData.geo_lat || 0,
geo_lon: detectionData.geo_lon || 0,
last_heartbeat: new Date(),
is_approved: false,
is_active: false
});
// Device not found - reject detection and require manual registration
console.log(`🚫 Detection rejected from unknown device ${detectionData.device_id} - device must be manually registered first`);
// Emit notification for new device requiring approval
req.io.emit('new_device_pending', {
device_id: detectionData.device_id,
timestamp: new Date().toISOString(),
message: `New device ${detectionData.device_id} requires approval`
});
console.log(`⚠️ New unapproved device ${detectionData.device_id} created, awaiting approval`);
return res.status(202).json({
return res.status(404).json({
success: false,
error: 'Device not approved',
message: 'Device has been registered but requires approval before it can send data',
error: 'Device not registered',
message: 'Device not found. Please register the device manually through the UI before sending data.',
device_id: detectionData.device_id,
approval_required: true
registration_required: true
});
}