From f18bac2db55439a5de3a9796b48cca09482ec641 Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Sat, 13 Sep 2025 12:26:21 +0200 Subject: [PATCH] Fix jwt-token --- server/models/index.js | 8 +++++++- server/routes/management.js | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server/models/index.js b/server/models/index.js index cdda53c..501dfe2 100644 --- a/server/models/index.js +++ b/server/models/index.js @@ -26,6 +26,7 @@ const Heartbeat = require('./Heartbeat')(sequelize); const User = require('./User')(sequelize); const AlertRule = require('./AlertRule')(sequelize); const AlertLog = require('./AlertLog')(sequelize); +const Tenant = require('./Tenant')(sequelize); // Define associations Device.hasMany(DroneDetection, { foreignKey: 'device_id', as: 'detections' }); @@ -43,6 +44,10 @@ AlertLog.belongsTo(AlertRule, { foreignKey: 'alert_rule_id', as: 'rule' }); DroneDetection.hasMany(AlertLog, { foreignKey: 'detection_id', as: 'alerts' }); AlertLog.belongsTo(DroneDetection, { foreignKey: 'detection_id', as: 'detection' }); +// Tenant associations +Tenant.hasMany(User, { foreignKey: 'tenant_id', as: 'users' }); +User.belongsTo(Tenant, { foreignKey: 'tenant_id', as: 'tenant' }); + module.exports = { sequelize, Device, @@ -50,5 +55,6 @@ module.exports = { Heartbeat, User, AlertRule, - AlertLog + AlertLog, + Tenant }; diff --git a/server/routes/management.js b/server/routes/management.js index 9e8d725..15d4311 100644 --- a/server/routes/management.js +++ b/server/routes/management.js @@ -7,6 +7,7 @@ const express = require('express'); const router = express.Router(); const jwt = require('jsonwebtoken'); const bcrypt = require('bcryptjs'); // Fixed: use bcryptjs instead of bcrypt +const { Op } = require('sequelize'); // Add Sequelize operators const { Tenant, User } = require('../models'); // Management-specific authentication middleware - NO shared auth with tenants