Fix jwt-token

This commit is contained in:
2025-09-18 06:32:07 +02:00
parent e76302530b
commit 8d446b76c8

View File

@@ -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: [{
@@ -115,6 +125,8 @@ router.get('/', authenticateToken, async (req, res) => {
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({
where: whereClause,