Fix jwt-token
This commit is contained in:
@@ -28,6 +28,9 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
|
|
||||||
// Get tenant from authenticated user context
|
// Get tenant from authenticated user context
|
||||||
const tenantId = req.tenantId;
|
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) {
|
if (!tenantId) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
@@ -36,6 +39,7 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tenant = await Tenant.findOne({ where: { slug: tenantId } });
|
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) {
|
if (!tenant) {
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
success: false,
|
success: false,
|
||||||
@@ -102,6 +106,12 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
const offset = (validatedPage - 1) * validatedLimit;
|
const offset = (validatedPage - 1) * validatedLimit;
|
||||||
|
|
||||||
// Query detections with device information (filtered by tenant)
|
// 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({
|
const detections = await DroneDetection.findAll({
|
||||||
where: whereClause,
|
where: whereClause,
|
||||||
include: [{
|
include: [{
|
||||||
@@ -114,6 +124,8 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
limit: validatedLimit,
|
limit: validatedLimit,
|
||||||
offset: offset
|
offset: offset
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(`🔍 Detections query - found ${detections.length} detections for tenant ${tenant.slug}`);
|
||||||
|
|
||||||
// Get total count for pagination (also filtered by tenant)
|
// Get total count for pagination (also filtered by tenant)
|
||||||
const totalCount = await DroneDetection.count({
|
const totalCount = await DroneDetection.count({
|
||||||
|
|||||||
Reference in New Issue
Block a user