Fix jwt-token
This commit is contained in:
@@ -105,7 +105,7 @@ router.post('/', validateRequest(detectorSchema), async (req, res) => {
|
||||
|
||||
// Handle heartbeat payload
|
||||
async function handleHeartbeat(req, res) {
|
||||
const { type, key, device_id, ...heartbeatData } = req.body;
|
||||
const { type, key, device_id, geo_lat, geo_lon, location_description, ...heartbeatData } = req.body;
|
||||
|
||||
console.log(`💓 Heartbeat received from device key: ${key}`);
|
||||
console.log('💗 Complete heartbeat data:', JSON.stringify(req.body, null, 2));
|
||||
@@ -124,13 +124,28 @@ async function handleHeartbeat(req, res) {
|
||||
let device = await Device.findOne({ where: { id: deviceId } });
|
||||
|
||||
if (!device) {
|
||||
// Create new device as unapproved
|
||||
device = await Device.create({
|
||||
// Create new device as unapproved with coordinates if provided
|
||||
const deviceData = {
|
||||
id: deviceId,
|
||||
name: `Device ${deviceId}`,
|
||||
last_heartbeat: new Date(),
|
||||
is_approved: false
|
||||
});
|
||||
};
|
||||
|
||||
// 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', {
|
||||
|
||||
Reference in New Issue
Block a user