const fs = require('fs');
const path = require('path');

console.log('🔍 RECHERCHE DE LA CONFIGURATION JWT RÉELLE\n');
console.log('='.repeat(60));

// Fichiers à examiner
const filesToCheck = [
  './dist/src/middlewares/auth.js',
  './dist/src/modules-admin/auth/controller.js', 
  './dist/src/app.js',
  './dist/src/modules/auth/controller.js'
];

function searchJWTConfig(filePath) {
  try {
    if (fs.existsSync(filePath)) {
      console.log(`\n📄 ${filePath}:`);
      const content = fs.readFileSync(filePath, 'utf8');
      
      // Chercher les configurations JWT
      const jwtMatches = content.match(/secret.*=.*['"]([^'"]+)['"]|SECRET.*:.*['"]([^'"]+)['"]|jwtSecret.*:.*['"]([^'"]+)['"]/gi);
      if (jwtMatches) {
        jwtMatches.forEach(match => {
          console.log('   🔐', match);
        });
      }
      
      // Chercher les stratégies Passport
      const passportMatches = content.match(/JwtStrategy|passport|fromExtractors|jwtFromRequest/gi);
      if (passportMatches) {
        console.log('   🛡️  Passport:', [...new Set(passportMatches)].join(', '));
      }
      
      // Chercher les clés secrètes
      const secretMatches = content.match(/secretOrKey.*:.*['"]([^'"]+)['"]|secret.*:.*['"]([^'"]+)['"]/gi);
      if (secretMatches) {
        secretMatches.forEach(match => {
          console.log('   🗝️ ', match);
        });
      }
    }
  } catch (error) {
    console.log(`   ❌ Erreur: ${error.message}`);
  }
}

// Examiner tous les fichiers
filesToCheck.forEach(searchJWTConfig);

// Chercher aussi dans les fichiers de configuration
console.log('\n🔎 Recherche dans les fichiers de config...');
const configFiles = fs.readdirSync('./dist/src').filter(file => 
  file.includes('config') || file.includes('Config')
);
configFiles.forEach(file => {
  searchJWTConfig(path.join('./dist/src', file));
});
