Fix jwt-token
This commit is contained in:
@@ -107,14 +107,16 @@ async function handleHeartbeat(req, res) {
|
|||||||
console.log(`💓 Heartbeat received from device key: ${key}`);
|
console.log(`💓 Heartbeat received from device key: ${key}`);
|
||||||
console.log('💗 Complete heartbeat data:', JSON.stringify(req.body, null, 2));
|
console.log('💗 Complete heartbeat data:', JSON.stringify(req.body, null, 2));
|
||||||
|
|
||||||
// If device_id is not provided, try to find device by key
|
// Use device_id if provided, otherwise use key as device identifier
|
||||||
let deviceId = device_id;
|
let deviceId = device_id || key;
|
||||||
if (!deviceId) {
|
|
||||||
// Try to extract device ID from key or use key as identifier
|
// Convert to integer if it's a numeric string
|
||||||
const keyMatch = key.match(/device[_-]?(\d+)/i);
|
if (typeof deviceId === 'string' && /^\d+$/.test(deviceId)) {
|
||||||
deviceId = keyMatch ? parseInt(keyMatch[1]) : key.hashCode();
|
deviceId = parseInt(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`📌 Using device ID: ${deviceId}`);
|
||||||
|
|
||||||
// Check if device exists and is approved
|
// Check if device exists and is approved
|
||||||
let device = await Device.findOne({ where: { id: deviceId } });
|
let device = await Device.findOne({ where: { id: deviceId } });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user