Fix jwt-token

This commit is contained in:
2025-09-17 20:05:46 +02:00
parent 571634642b
commit 5d61bb50ed
4 changed files with 41 additions and 38 deletions

View File

@@ -155,13 +155,15 @@ async function handleHeartbeat(req, res) {
if (!device.is_approved) {
console.log(`🚫 Heartbeat rejected from unapproved device ${deviceId}`);
// Emit reminder notification
req.io.emit('device_approval_reminder', {
device_id: deviceId,
device_key: key,
timestamp: new Date().toISOString(),
message: `Device ${deviceId} (${key}) still awaiting approval`
});
// Emit reminder notification to tenant room only
if (device.tenant_id) {
req.io.to(`tenant_${device.tenant_id}`).emit('device_approval_reminder', {
device_id: deviceId,
device_key: key,
timestamp: new Date().toISOString(),
message: `Device ${deviceId} (${key}) still awaiting approval`
});
}
return res.status(403).json({
success: false,
@@ -195,14 +197,16 @@ async function handleHeartbeat(req, res) {
const heartbeat = await Heartbeat.create(heartbeatRecord);
// Emit real-time update via Socket.IO (from original heartbeat route)
req.io.emit('device_heartbeat', {
device_id: deviceId,
device_key: key,
timestamp: heartbeat.received_at,
status: 'online',
...heartbeatData
});
// Emit real-time update via Socket.IO to tenant room only
if (device.tenant_id) {
req.io.to(`tenant_${device.tenant_id}`).emit('device_heartbeat', {
device_id: deviceId,
device_key: key,
timestamp: heartbeat.received_at,
status: 'online',
...heartbeatData
});
}
console.log(`✅ Heartbeat recorded for device ${deviceId}`);
@@ -261,12 +265,14 @@ async function handleDetection(req, res) {
if (!device.is_approved) {
console.log(`🚫 Detection rejected from unapproved device ${detectionData.device_id}`);
// Emit reminder notification
req.io.emit('device_approval_reminder', {
device_id: detectionData.device_id,
timestamp: new Date().toISOString(),
message: `Device ${detectionData.device_id} still awaiting approval`
});
// Emit reminder notification to tenant room only
if (device.tenant_id) {
req.io.to(`tenant_${device.tenant_id}`).emit('device_approval_reminder', {
device_id: detectionData.device_id,
timestamp: new Date().toISOString(),
message: `Device ${detectionData.device_id} still awaiting approval`
});
}
return res.status(403).json({
success: false,