Fix jwt-token

This commit is contained in:
2025-09-16 07:14:33 +02:00
parent 628bb94737
commit c5046e76a0

View File

@@ -5,12 +5,22 @@ if (process.env.NODE_ENV !== 'test') {
require('dotenv').config(); require('dotenv').config();
} }
// Check if models are already initialized (for tests) // Function to get current models (checks global models each time)
if (global.__TEST_MODELS__) { function getCurrentModels() {
if (process.env.NODE_ENV === 'test' && global.__TEST_MODELS__) {
console.log(`🔧 DEBUG: Using global test models from models/index.js`); console.log(`🔧 DEBUG: Using global test models from models/index.js`);
module.exports = global.__TEST_MODELS__; return global.__TEST_MODELS__;
} else { }
// If no global models, use the default cached models
if (!module.exports._defaultModels) {
console.log(`🔧 DEBUG: Creating new models instance in models/index.js`); console.log(`🔧 DEBUG: Creating new models instance in models/index.js`);
module.exports._defaultModels = createDefaultModels();
}
return module.exports._defaultModels;
}
function createDefaultModels() {
// Configure database based on environment // Configure database based on environment
let sequelize; let sequelize;
if (process.env.NODE_ENV === 'test') { if (process.env.NODE_ENV === 'test') {