From cd436070cd9462dbdf6df508f91df9057711f6ab Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Thu, 14 Aug 2025 11:52:52 +0000 Subject: [PATCH] Show assigned groups for users in the system Update the API to include user groups in the user data endpoint and add frontend logging for user details. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 31f9bd88-0285-4787-81b3-31ceeea5a08b Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/31f9bd88-0285-4787-81b3-31ceeea5a08b/7ff921U --- client/src/components/CustomerOrderForm.tsx | 10 ++++++ server/localAuth.ts | 35 ++++++++++++++------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/client/src/components/CustomerOrderForm.tsx b/client/src/components/CustomerOrderForm.tsx index 5347bbb..b553761 100644 --- a/client/src/components/CustomerOrderForm.tsx +++ b/client/src/components/CustomerOrderForm.tsx @@ -68,6 +68,16 @@ export function CustomerOrderForm({ const { user } = useAuthUnified(); const { selectedStoreId } = useStore(); + // DEBUG: Log user data to see what we actually receive + console.log("🔍 FRONTEND USER DEBUG:", { + user: user, + userRole: user?.role, + userGroups: user?.userGroups, + userGroupsType: typeof user?.userGroups, + userGroupsLength: user?.userGroups?.length, + fullUserObject: JSON.stringify(user, null, 2) + }); + // Fetch groups for store selection const { data: groups = [] } = useQuery({ queryKey: ['/api/groups'], diff --git a/server/localAuth.ts b/server/localAuth.ts index 83d50cb..69f4aa1 100644 --- a/server/localAuth.ts +++ b/server/localAuth.ts @@ -188,20 +188,33 @@ export function setupLocalAuth(app: Express) { app.get("/api/logout", logoutHandler); // Get current user - app.get("/api/user", (req, res) => { + app.get("/api/user", async (req, res) => { if (!req.isAuthenticated()) { return res.status(401).json({ message: "Non authentifié" }); } - const user = req.user as SelectUser; - res.json({ - id: user.id, - username: user.username, - email: user.email, - firstName: user.firstName, - lastName: user.lastName, - role: user.role, - passwordChanged: user.passwordChanged - }); + + try { + const userId = (req.user as SelectUser).id; + const userWithGroups = await storage.getUserWithGroups(userId); + + if (!userWithGroups) { + return res.status(404).json({ message: "Utilisateur non trouvé" }); + } + + res.json({ + id: userWithGroups.id, + username: userWithGroups.username, + email: userWithGroups.email, + firstName: userWithGroups.firstName, + lastName: userWithGroups.lastName, + role: userWithGroups.role, + passwordChanged: userWithGroups.passwordChanged, + userGroups: userWithGroups.userGroups || [] + }); + } catch (error) { + console.error("Error fetching user with groups:", error); + res.status(500).json({ message: "Erreur lors de la récupération des données utilisateur" }); + } }); // Check if default credentials should be shown