Files
LogiFlow/DLC-PRODUCTION-FIX-FINAL.md
T
michaelschal a2110a84b4 Fix issue where user groups were not correctly assigned for product creation
Correct the user API endpoint to include user groups in the response, resolving an issue where products were created with incorrect or default group assignments due to missing group data.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/KQQafdY
2025-08-12 15:28:48 +00:00

2.1 KiB

Fix Final Production - Problème UserGroups

Problème Identifié en Production

Les logs frontend montraient :

Customer Order Frontend Debug: {
  userRole: 'employee', 
  selectedStoreId: 1, 
  userGroups: undefined,  // ❌ PROBLÈME ICI !
  initialGroupId: undefined,
  availableGroups: [...]
}
Final groupId selected: 1  // ❌ Fallback utilisé au lieu du groupe assigné

Cause Racine Trouvée

✅ Backend fonctionne correctement

  • storage.getUserWithGroups(id) retourne bien les groupes
  • passport.deserializeUser charge les userGroups

❌ Route /api/user manquait userGroups

// AVANT (Production cassée)
app.get("/api/user", (req: any, res) => {
  res.json({
    id: req.user.id,
    role: req.user.role,
    // userGroups: MANQUANT ! ❌
  });
});

// APRÈS (Production fixée)  
app.get("/api/user", (req: any, res) => {
  res.json({
    id: req.user.id,
    role: req.user.role,
    userGroups: req.user.userGroups || [] // ✅ AJOUTÉ !
  });
});

Fix Appliqué

1. Route /api/user corrigée

  • ✅ Ajout de userGroups dans la réponse JSON
  • ✅ Logs debug pour tracer les données utilisateur

2. Logique Frontend maintenant fonctionnelle

// Avec userGroups maintenant disponible :
if (user?.userGroups?.[0]?.groupId) {
  // ✅ Utilisera le groupe assigné (groupId: 2)
  groupId = user.userGroups[0].groupId;
}

Résultat Attendu Production

Employé assigné magasin #2 (Houdemont) :

  1. Login → /api/user retourne userGroups: [{ groupId: 2, group: { name: 'Houdemont' } }]
  2. Frontend → Détecte user.userGroups[0].groupId = 2
  3. Création DLC → groupId: 2 (groupe assigné prioritaire)
  4. Création commande → groupId: 2 (groupe assigné prioritaire)
  5. Résultat → DLC et commandes apparaissent dans magasin #2 ✅

Logs Debug Production

Les nouveaux logs vont confirmer :

🔍 PRODUCTION /api/user - req.user: {
  id: '_1753266816257',
  role: 'employee', 
  hasUserGroups: true,
  userGroupsLength: 1,
  userGroups: [{ groupId: 2, groupName: 'Houdemont' }]
}

DÉPLOIEMENT IMMÉDIAT REQUIS - FIX DEFINITIF