Fix jwt-token

This commit is contained in:
2025-09-07 12:53:35 +02:00
parent 17618d35ef
commit 25701f0c9b

View File

@@ -107,14 +107,16 @@ async function handleHeartbeat(req, res) {
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;
if (!deviceId) {
// Try to extract device ID from key or use key as identifier
const keyMatch = key.match(/device[_-]?(\d+)/i);
deviceId = keyMatch ? parseInt(keyMatch[1]) : key.hashCode();
// Use device_id if provided, otherwise use key as device identifier
let deviceId = device_id || key;
// Convert to integer if it's a numeric string
if (typeof deviceId === 'string' && /^\d+$/.test(deviceId)) {
deviceId = parseInt(deviceId);
}
console.log(`📌 Using device ID: ${deviceId}`);
// Check if device exists and is approved
let device = await Device.findOne({ where: { id: deviceId } });