From 8d446b76c8c0f75922e2028881333d7948d6296f Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Thu, 18 Sep 2025 06:32:07 +0200 Subject: [PATCH] Fix jwt-token --- server/routes/detections.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/routes/detections.js b/server/routes/detections.js index d3f9451..d82f339 100644 --- a/server/routes/detections.js +++ b/server/routes/detections.js @@ -28,6 +28,9 @@ router.get('/', authenticateToken, async (req, res) => { // Get tenant from authenticated user context const tenantId = req.tenantId; + console.log(`🔍 Detections query - tenantId from req: ${tenantId}`); + console.log(`🔍 Detections query - req.user.tenant_id: ${req.user?.tenant_id}`); + if (!tenantId) { return res.status(400).json({ success: false, @@ -36,6 +39,7 @@ router.get('/', authenticateToken, async (req, res) => { } const tenant = await Tenant.findOne({ where: { slug: tenantId } }); + console.log(`🔍 Detections query - found tenant:`, tenant ? { id: tenant.id, slug: tenant.slug, name: tenant.name } : 'null'); if (!tenant) { return res.status(404).json({ success: false, @@ -102,6 +106,12 @@ router.get('/', authenticateToken, async (req, res) => { const offset = (validatedPage - 1) * validatedLimit; // Query detections with device information (filtered by tenant) + console.log(`🔍 Detections query - filtering devices by tenant_id: ${tenant.id}`); + + // Debug: Show all devices and their tenant assignments + const allDevices = await Device.findAll({ attributes: ['id', 'name', 'tenant_id'] }); + console.log(`🔍 All devices in database:`, allDevices.map(d => ({ id: d.id, name: d.name, tenant_id: d.tenant_id }))); + const detections = await DroneDetection.findAll({ where: whereClause, include: [{ @@ -114,6 +124,8 @@ router.get('/', authenticateToken, async (req, res) => { limit: validatedLimit, offset: offset }); + + console.log(`🔍 Detections query - found ${detections.length} detections for tenant ${tenant.slug}`); // Get total count for pagination (also filtered by tenant) const totalCount = await DroneDetection.count({